解决在现有Android项目中集成Flutter遇到的问题

如何添加Flutter到现有Android项目

Flutter官方有详细的文档, 参考文档即可。

集成过程中遇到的神坑

主Module名称一定要为"app"

如果主Module名称不是"app", 执行Flutter#createView后,会出现native层的崩溃。并且会出现错误信息VM snapshot must be valid, 崩溃信息如下:

#1 main

SIGABRT

解析原始
1 #00 pc 0001a52c /system/lib/libc.so (abort+63) [armeabi-v7a]
2 #01 pc 0053ea03 /data/app/com.xunlei.downloadprovider-hhbn6UtrgbvSTxvfZ3bDQQ==/lib/arm/libflutter.so [armeabi-v7a]
3 #02 pc 00536ba3 /data/app/com.xunlei.downloadprovider-hhbn6UtrgbvSTxvfZ3bDQQ==/lib/arm/libflutter.so [armeabi-v7a]
4 #03 pc 00092f75 /data/app/com.xunlei.downloadprovider-hhbn6UtrgbvSTxvfZ3bDQQ==/oat/arm/base.odex (oatexec+73589) [armeabi]
5 java:
6 io.flutter.view.FlutterNativeView.attach(FlutterNativeView.java:153)
7 io.flutter.view.FlutterNativeView.(FlutterNativeView.java:38)
8 io.flutter.view.FlutterNativeView.(FlutterNativeView.java:32)
9 io.flutter.facade.Flutter.createView(Flutter.java:73)
10 com.xunlei.downloadprovider.frame.MainTabActivity.onKeyDown(MainTabActivity.java:840)
11 android.view.KeyEvent.dispatch(KeyEvent.java:2758)
12 android.app.Activity.dispatchKeyEvent(Activity.java:3459)
13 com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:418)
14 android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:5233)
15 android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5105)
16 android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4623)
17 android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4676)
18 android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4642)
19 android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4769)
20 android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4650)
21 android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4826)
22 android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4623)
23 android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4676)
24 android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4642)
25 android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4650)
26 android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4623)
27 android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4676)
28 android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4642)
29 android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4802)
30 android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4963)
31 android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2597)
32 android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:2158)
33 android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:2149)
34 android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2572)
35 android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
36 android.os.MessageQueue.nativePollOnce(Native Method)
37 android.os.MessageQueue.next(MessageQueue.java:379)
38 android.os.Looper.loop(Looper.java:144)
39 android.app.ActivityThread.main(ActivityThread.java:7383)
40 java.lang.reflect.Method.invoke(Native Method)
41 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
42 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)

不能使用gradle的productFlavor属性

项目中如果使用了productFlavor属性进行差异化打包,会出现native层的崩溃。并且会出现错误信息VM snapshot must be valid.

你可能感兴趣的:(原创,android,flutter)