Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter工程加入到已有的Native APP,该如何集成? #9

Closed
ruanchaohouzi opened this issue Mar 8, 2019 · 17 comments
Closed

Comments

@ruanchaohouzi
Copy link

再问一个问题,如果我把Flutter工程加入到已有的NativeAPP中 ,采取官方的集成方式https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps 请问Native工程如何接入flutter_boost???

@moonljt521
Copy link

@ruanchaohouzi 要在你的flutter module里的接入flutter_boost, 里边找yaml进行配置

@ruanchaohouzi
Copy link
Author

@ruanchaohouzi 要在你的flutter module里的接入flutter_boost, 里边找yaml进行配置

@moonljt521 对呀,flutter module里的已经接入了flutter_boost,我问的是Native APP工程该怎么集成?也就是是Native的Application已经不是FlutterApplication而是我自己的Application,我该如何初始化flutter_boost???

@nightwolf-chen
Copy link
Contributor

I hope I have understood your problem correctly.

We haven't tried this before. I believe there is some way to do it. The flutter_boost contains three kinds of source code for Dart, iOS, and Android. In my understanding, you could first download the source package(flutter packages get helps you to do that) and save it somewhere then you will probably need to config dependency for each kind of source respectively.

Dart

you just need to add flutter_boost to dependency section normally.

iOS

Try to add a dependency in your Podfile pointing source under flutter_boost/ios/Classes

Android

Config your Gradle build file pointing to source under flutter_boost/android

@ruanchaohouzi
Copy link
Author

I hope I have understood your problem correctly.

We haven't tried this before. I believe there is some way to do it. The flutter_boost contains three kinds of source code for Dart, iOS, and Android. In my understanding, you could first download the source package(flutter packages get helps you to do that) and save it somewhere then you will probably need to config dependency for each kind of source respectively.

Dart

you just need to add flutter_boost to dependency section normally.

iOS

Try to add a dependency in your Podfile pointing source under flutter_boost/ios/Classes

Android

Config your Gradle build file pointing to source under flutter_boost/android

@nightwolf-chen 对,你理解的正确,我问的就是这一步的操作:
Android
Config your Gradle build file pointing to source under flutter_boost/android
(1)我已经在app 的 gradle里面配置了compile project(path: ':flutter_boost')
(2)请问我的Application里面该如何配置,需要把我原有的Application改成FlutterApplication吗?然后在进行初始化??
image

@ruanchaohouzi
Copy link
Author

@nightwolf-chen 我觉得我说的这种接入方式,你们文档最好还是能够完善一点,因为现在很多都是在原有的Native过程里面接入Flutter module,而不是采取现有的Flutter工程,这是由于以前已有Native 工程的限制,而你的demo文档是直接在flutter工程接入flutter_boost

@zsmjhtn
Copy link

zsmjhtn commented Mar 8, 2019

@nightwolf-chen 我觉得我说的这种接入方式,你们文档最好还是能够完善一点,因为现在很多都是在原有的Native过程里面接入Flutter module,而不是采取现有的Flutter工程,这是由于以前已有Native 工程的限制,而你的demo文档是直接在flutter工程接入flutter_boost

我把aos的代码全部copy到native工程,自己的flutte_module只是加了个一个 dependency:flutter_boost。
在加flutter_boost之前,自己的flutte_module 打成aar没问题。
加了flutter_boost之后,自己的flutte_module 打成aar抛错
image
估计自己的flutte_module和dependency:flutter_boost的:build:gradle,buildTollVersion 不同有关

@Yacumima
Copy link
Collaborator

Yacumima commented Mar 8, 2019

I hope I have understood your problem correctly.
We haven't tried this before. I believe there is some way to do it. The flutter_boost contains three kinds of source code for Dart, iOS, and Android. In my understanding, you could first download the source package(flutter packages get helps you to do that) and save it somewhere then you will probably need to config dependency for each kind of source respectively.

Dart

you just need to add flutter_boost to dependency section normally.

iOS

Try to add a dependency in your Podfile pointing source under flutter_boost/ios/Classes

Android

Config your Gradle build file pointing to source under flutter_boost/android

@nightwolf-chen 对,你理解的正确,我问的就是这一步的操作:
Android
Config your Gradle build file pointing to source under flutter_boost/android
(1)我已经在app 的 gradle里面配置了compile project(path: ':flutter_boost')
(2)请问我的Application里面该如何配置,需要把我原有的Application改成FlutterApplication吗?然后在进行初始化??
image

推荐将Application改成FlutterApplication,但如果原来的工程已经有自定义的Application,也可以在onCreate方法中加入:FlutterMain.startInitialization(this);

如果想在现有工程的基础上引入Flutter做混合开发有两种思路:
1.以现有工程作为主工程,新建Flutter的工程,将flutter module工程作为模块引入。
2.新建flutter工程作为主工程,将现有Android和iOS工程分别替换工程中的Android和iOS文件夹。

两种都有官方支持,也都可以接入flutter_boost . 推荐使用第二种,实施简单,也可以较方便的桥接原生工程的能力。

@zsmjhtn
Copy link

zsmjhtn commented Mar 8, 2019

请问我将

I hope I have understood your problem correctly.
We haven't tried this before. I believe there is some way to do it. The flutter_boost contains three kinds of source code for Dart, iOS, and Android. In my understanding, you could first download the source package(flutter packages get helps you to do that) and save it somewhere then you will probably need to config dependency for each kind of source respectively.

Dart

you just need to add flutter_boost to dependency section normally.

iOS

Try to add a dependency in your Podfile pointing source under flutter_boost/ios/Classes

Android

Config your Gradle build file pointing to source under flutter_boost/android

@nightwolf-chen 对,你理解的正确,我问的就是这一步的操作:
Android
Config your Gradle build file pointing to source under flutter_boost/android
(1)我已经在app 的 gradle里面配置了compile project(path: ':flutter_boost')
(2)请问我的Application里面该如何配置,需要把我原有的Application改成FlutterApplication吗?然后在进行初始化??
image

推荐将Application改成FlutterApplication,但如果原来的工程已经有自定义的Application,也可以在onCreate方法中加入:FlutterMain.startInitialization(this);

如果想在现有工程的基础上引入Flutter做混合开发有两种思路:
1.以现有工程作为主工程,新建Flutter的工程,将flutter module工程作为模块引入。
2.新建flutter工程作为主工程,将现有Android和iOS工程分别替换工程中的Android和iOS文件夹。

两种都有官方支持,也都可以接入flutter_boost . 推荐使用第二种,实施简单,也可以较方便的桥接原生工程的能力。

请问下,就安卓来说:
1方案,你是将flutter_boost整个打成aar,然后native项目依赖这个aar吗?这样的话,BoostFlutterActivity是在aar中,BoostFlutterActivity实现类都打在aar中,这些页面怎么和native项目已有的页面交互?
然后,我把BoostFlutterActivity以及它的实现类都放在native项目中,aar中只写dart的页面,但是又遇到了native项目需要依赖 aar 中dart的 xservice_kit 的问题。
方案2:因为是flutter工程,不知道什么原因,copy进去的native项目无法build/clean,不能单独执行app的build,AS自带的一些lint检测也都无用了,配置文件标红、代码link跳转有问题。失去了原生项目的sync、clean和build,对于原生代码的问题排查比较麻烦。请问你们是怎么解决的?

@Yacumima
Copy link
Collaborator

Yacumima commented Mar 8, 2019

请问我将

I hope I have understood your problem correctly.
We haven't tried this before. I believe there is some way to do it. The flutter_boost contains three kinds of source code for Dart, iOS, and Android. In my understanding, you could first download the source package(flutter packages get helps you to do that) and save it somewhere then you will probably need to config dependency for each kind of source respectively.

Dart

you just need to add flutter_boost to dependency section normally.

iOS

Try to add a dependency in your Podfile pointing source under flutter_boost/ios/Classes

Android

Config your Gradle build file pointing to source under flutter_boost/android

@nightwolf-chen 对,你理解的正确,我问的就是这一步的操作:
Android
Config your Gradle build file pointing to source under flutter_boost/android
(1)我已经在app 的 gradle里面配置了compile project(path: ':flutter_boost')
(2)请问我的Application里面该如何配置,需要把我原有的Application改成FlutterApplication吗?然后在进行初始化??
image

推荐将Application改成FlutterApplication,但如果原来的工程已经有自定义的Application,也可以在onCreate方法中加入:FlutterMain.startInitialization(this);
如果想在现有工程的基础上引入Flutter做混合开发有两种思路:
1.以现有工程作为主工程,新建Flutter的工程,将flutter module工程作为模块引入。
2.新建flutter工程作为主工程,将现有Android和iOS工程分别替换工程中的Android和iOS文件夹。
两种都有官方支持,也都可以接入flutter_boost . 推荐使用第二种,实施简单,也可以较方便的桥接原生工程的能力。

请问下,就安卓来说:
1方案,你是将flutter_boost整个打成aar,然后native项目依赖这个aar吗?这样的话,BoostFlutterActivity是在aar中,BoostFlutterActivity实现类都打在aar中,这些页面怎么和native项目已有的页面交互?
然后,我把BoostFlutterActivity以及它的实现类都放在native项目中,aar中只写dart的页面,但是又遇到了native项目需要依赖 aar 中dart的 xservice_kit 的问题。
方案2:因为是flutter工程,不知道什么原因,copy进去的native项目无法build/clean,不能单独执行app的build,AS自带的一些lint检测也都无用了,配置文件标红、代码link跳转有问题。失去了原生项目的sync、clean和build,对于原生代码的问题排查比较麻烦。请问你们是怎么解决的?

====答=====
1方案:BoostFlutterActivity在aar中,BoostFlutterActivity的实现类放在native工程中。可以查看 .flutter-plugins文件,里面列出的plugin都需要打成aar让主工程依赖,这需要去实现一个简单gradle插件。
2方案:native的Android工程标准吗?作为application的那个模块名字必须时app。通常我们会开两个IDE界面,一个open flutter的工程用来开发dart,一个open flutter工程下的Android目录,用来开发Java。

@TinoGuo
Copy link

TinoGuo commented Mar 8, 2019

@Yacumima 你好,plugin生成的aar如何管理?如果用maven的话,就要把所有的plugin都上传,有没有比较高效的方案?或者有比较好的reference可以借鉴。谢谢!

@zsmjhtn
Copy link

zsmjhtn commented Mar 8, 2019

请问我将

I hope I have understood your problem correctly.
We haven't tried this before. I believe there is some way to do it. The flutter_boost contains three kinds of source code for Dart, iOS, and Android. In my understanding, you could first download the source package(flutter packages get helps you to do that) and save it somewhere then you will probably need to config dependency for each kind of source respectively.

Dart

you just need to add flutter_boost to dependency section normally.

iOS

Try to add a dependency in your Podfile pointing source under flutter_boost/ios/Classes

Android

Config your Gradle build file pointing to source under flutter_boost/android

@nightwolf-chen 对,你理解的正确,我问的就是这一步的操作:
Android
Config your Gradle build file pointing to source under flutter_boost/android
(1)我已经在app 的 gradle里面配置了compile project(path: ':flutter_boost')
(2)请问我的Application里面该如何配置,需要把我原有的Application改成FlutterApplication吗?然后在进行初始化??
image

推荐将Application改成FlutterApplication,但如果原来的工程已经有自定义的Application,也可以在onCreate方法中加入:FlutterMain.startInitialization(this);
如果想在现有工程的基础上引入Flutter做混合开发有两种思路:
1.以现有工程作为主工程,新建Flutter的工程,将flutter module工程作为模块引入。
2.新建flutter工程作为主工程,将现有Android和iOS工程分别替换工程中的Android和iOS文件夹。
两种都有官方支持,也都可以接入flutter_boost . 推荐使用第二种,实施简单,也可以较方便的桥接原生工程的能力。

请问下,就安卓来说:
1方案,你是将flutter_boost整个打成aar,然后native项目依赖这个aar吗?这样的话,BoostFlutterActivity是在aar中,BoostFlutterActivity实现类都打在aar中,这些页面怎么和native项目已有的页面交互?
然后,我把BoostFlutterActivity以及它的实现类都放在native项目中,aar中只写dart的页面,但是又遇到了native项目需要依赖 aar 中dart的 xservice_kit 的问题。
方案2:因为是flutter工程,不知道什么原因,copy进去的native项目无法build/clean,不能单独执行app的build,AS自带的一些lint检测也都无用了,配置文件标红、代码link跳转有问题。失去了原生项目的sync、clean和build,对于原生代码的问题排查比较麻烦。请问你们是怎么解决的?

====答=====
1方案:BoostFlutterActivity在aar中,BoostFlutterActivity的实现类放在native工程中。可以查看 .flutter-plugins文件,里面列出的plugin都需要打成aar让主工程依赖,这需要去实现一个简单gradle插件。
2方案:native的Android工程标准吗?作为application的那个模块名字必须时app。通常我们会开两个IDE界面,一个open flutter的工程用来开发dart,一个open flutter工程下的Android目录,用来开发Java。

谢谢!我再去试试。
针对方案2,我刚才才发现,flutter项目有时会在编译器右上角提示另开一个ide去edit。双开能解决此问题,一个开发/检测dart,一个开发/检测android项目(必须只导入android项目,build/clean/sync才会正常工作)。
作为application的那个模块名字必须是app,这个问题也知道了,flutter启动编译只会去固定路径 android/app/src/main/AndroidManifest.xml 找配置文件

@Yacumima
Copy link
Collaborator

@Yacumima 你好,plugin生成的aar如何管理?如果用maven的话,就要把所有的plugin都上传,有没有比较高效的方案?或者有比较好的reference可以借鉴。谢谢!

是的,我们现在也是依赖maven来管理,只是通过定制的gradle插件实现了自动化依赖而已。如果有更好的思路,欢迎和我们分享交流~

@heluotian
Copy link

@ruanchaohouzi 请问您在自己的application中初始化成功了吗? 我的是MyApplicationLike (extend DefaultApplicationLike 集成的tinker application) 不是继承的FlutterApplication ,编译时报错不兼容的类型: MyApplicationLike无法转换为Application,请问您遇到过吗,有解决吗?谢谢

@jp1017
Copy link

jp1017 commented Mar 12, 2019

作为application的那个模块名字必须是app,这个问题也知道了,flutter启动编译只会去固定路径 android/app/src/main/AndroidManifest.xml 找配置文件

这个默认的吗,还是哪里配置,我也有这个路径,怎么一编译,会自动出来个.android文件夹?

#16

@jp1017
Copy link

jp1017 commented Mar 13, 2019

路由控制方案

具体怎么搞的,native和flutter页面跳来跳去,怎么搞呢,性能如何?

@ethanhua
Copy link

采用flutter 官方方案在原生android项目引入flutter_boost(app gradle里面include:flutter_boost)后,本地能编译通过,编译集群上面报Could not resolve project :flutter_boost. 需要做什么配置吗?

@123lxw123
Copy link

123lxw123 commented Jul 24, 2019

I hope I have understood your problem correctly.
We haven't tried this before. I believe there is some way to do it. The flutter_boost contains three kinds of source code for Dart, iOS, and Android. In my understanding, you could first download the source package(flutter packages get helps you to do that) and save it somewhere then you will probably need to config dependency for each kind of source respectively.

Dart

you just need to add flutter_boost to dependency section normally.

iOS

Try to add a dependency in your Podfile pointing source under flutter_boost/ios/Classes

Android

Config your Gradle build file pointing to source under flutter_boost/android

@nightwolf-chen 对,你理解的正确,我问的就是这一步的操作:
Android
Config your Gradle build file pointing to source under flutter_boost/android
(1)我已经在app 的 gradle里面配置了compile project(path: ':flutter_boost')
(2)请问我的Application里面该如何配置,需要把我原有的Application改成FlutterApplication吗?然后在进行初始化??
image

推荐将Application改成FlutterApplication,但如果原来的工程已经有自定义的Application,也可以在onCreate方法中加入:FlutterMain.startInitialization(this);

如果想在现有工程的基础上引入Flutter做混合开发有两种思路:
1.以现有工程作为主工程,新建Flutter的工程,将flutter module工程作为模块引入。
2.新建flutter工程作为主工程,将现有Android和iOS工程分别替换工程中的Android和iOS文件夹。

两种都有官方支持,也都可以接入flutter_boost . 推荐使用第二种,实施简单,也可以较方便的桥接原生工程的能力。

@Yacumima 请教一下方案二,将现有Android和iOS工程分别替换工程中的Android和iOS文件夹之后还需要哪些操作才能完成集成?如果有资料链接可以参考下就更好了,搜索到资料没有涉及这种场景。十分感谢🙏

nightfallsad added a commit that referenced this issue Sep 22, 2020
@joker-fu joker-fu mentioned this issue Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants