Flutter - 从现有的android项目导入 [英] Flutter - Import from existing android project

查看:227
本文介绍了Flutter - 从现有的android项目导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个大约75%完成的Android项目。我需要一个类似的iOS应用程序。



我可以导入这个项目来扑动吗?怎么样?



另外,flutter会支持我在这个项目中使用的库吗?

解决方案

Flutter应用程序完全不同,即不像Android,也不像iOS。 Flutter有自己的架构,因此有自己的插件等。



摘要



,你不能现有的Android代码转换为Flutter的 Dart 代码,这是启用跨平台行为所必需的,因为Flutter SDK使用的所有代码都必须写入Dart。



但是,您可以将Android代码包含在Android文件夹中并尝试将它与Flutter SDK集成,这可能比完全在Dart中重写更多的工作。这也是您通常想要做的事情,因为原生的Android和iOS代码最有意义地用于启用Flutter无法实现的功能,其形式为插件



还有第三种方法,就是你保留您的Android代码,只使用Flutter 添加功能。这很难实现,因为您必须创建一个从Android代码切换到Flutter的界面。使用此功能,您还需要在Flutter或本机iOS中重写iOS的剩余部分,这对您没有任何帮助。



精化



对此有一个很直接的答案。



Flutter 是一个层在上面本机SDK的。 这意味着 可以保留你的代码,因为如果你曾经看过Flutter 项目,你会发现其中有,目前,基本上三个结构你可以使用:




  • lib Dart 代码+文件的文件夹Flutter需要例如包括插件,简称: Dart代码 Flutter


  • iOS Objective-C Swift 代码的文件夹,其中还包含常用的iOS配件


  • android Java Kotlin的文件夹(或C ++)代码和所有其他gradle文件等。




这意味着如果您愿意,可以使用本机代码,但您不需要这样做。



你可以完全忽略 android ios 开发期间的文件夹,如果你想



很可能你只是修改应用程序图标,名称,版本名称,许可证密钥等方面在您的原生代码中。



Flutter 目标是在Dart中编写所有代码并且仅在Flutter SDK,这意味着您现有的Android代码可以包含在项目中,但它对iOS没有任何用处,因为所有跨平台工作都是在Dart中使用 Flutter SDK



结论



如果您真的想切换到Flutter SDK,那么您最好的选择是完全切换到Flutter,即重写 Dart 中的所有功能。



将Android代码转换为Flutter代码没有导入可能性。如果它们是用同一种语言编写的话,这甚至都不会起作用,因为Flutter架构完全不同,你构建应用程序的方式与Android应用程序没有太大关系。



如果你认为学习Dart并重写你的跨平台应用程序是不值得的,但你仍然需要iOS支持,我建议你用iOS本机编写,但我对这个问题的一般建议是在Dart中重写整个应用程序。 / p>

I am currently working on an android project which is ~75% complete. I need a similar application for iOS.

Can I import this project to flutter? How?

Also, will flutter supports the libraries I have used in this project?

解决方案

Flutter applications work completely different, i.e. not like Android nor like iOS. Flutter has its own architecture and therefore own plugins etc.

Summary

No, you cannot convert your existing Android code into Dart code for Flutter, which is necessary to enable cross-platform behavior because all code used by the Flutter SDK has to be written in Dart.

However, you could make use of your Android code by just including it in the Android folder and trying to integrate it with the Flutter SDK, which will probably be all lot more work than just rewriting it entirely in Dart. This is also not what you generally want to do because native Android and iOS code make most sense to be used to enable features that you cannot achieve with Flutter, in the form of plugins.

There is also a third approach, which is that you keep your Android code and only add features with Flutter. This is harder to implement because you will have to create an interface to "switch" to Flutter from Android code. Using this you would also need to rewrite your remaining parts for iOS in either Flutter or native iOS, which does not help you at all.

Elaboration

There is a pretty straight forward answer to this.

Flutter is a layer on top of the native SDK's. This means that you could keep your code because, if you ever took a look into a Flutter project, you would see that in it there are, at the moment, essentially three structures you can work with:

  • lib folder for Dart code + files Flutter needs to e.g. include plugins, short: Dart code for Flutter

  • iOS folder for either Objective-C or Swift code, which also includes the usual iOS accessories

  • android folder for either Java or Kotlin (or C++) code and all other gradle files etc.

This means that you can use native code if you want to, but you do not need to do it.

You can completely ignore the android and ios folders during development if you want to`.

Most likely you will just be modifying aspects like the app icon, name, version name, license keys etc. in your native code.

Flutter's goal is to write all code in Dart and only in the Flutter SDK, which means that your existing Android code could be included in the project, but it will not have any use for iOS because all cross-platform work is done in Dart making use of the Flutter SDK.

Conclusion

If you really want to switch to the Flutter SDK, your best choice is entirely switching to Flutter, i.e. rewriting all features in Dart.

There is no "import" possibility to "convert" Android code to Flutter code. This would not even work if they were written in the same language because the Flutter architecture is completely different and the way you build apps is not remotely related to Android applications.

If you think that learning Dart and rewriting your application for cross-platform is not worth it but you still want iOS support, I would suggest you to write in iOS native, but my general suggestion for the problem is rewriting the whole application in Dart.

这篇关于Flutter - 从现有的android项目导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆