Flutter 81: illustration of Android Native integrated fluterboost small attempt

Posted by Velausanakha on Sun, 29 Mar 2020 15:55:23 +0200

In a historical project, Xiaocai has connected to the Flutter Module and used fluterboost as the Platform Channel bridge. However, there are many problems in the actual development, only two impressive small problems are recorded;

Problem 1:. so file confusion

problem analysis

The NDK used in the history project of the small dish is armeabi, but after accessing the Flutter, armeabi-v7a needs to be used. So files corresponding to armeabi-v7a are added in the project to make the NDK support armeabi-v7a. The small dish test allows or debug s the package directly, while the release package directly crashes, suggesting that libc.so cannot be found;

** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'Xiaomi/kenzo/kenzo:6.0.1/MMB29M/V8.5.4.0.MHOCNED:user/release-keys'
Revision: '0'
ABI: 'arm'
pid: 2380, tid: 2380, name: com.ace.test  >>> com.ace.test <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: '[FATAL:flutter/shell/platform/android/library_loader.cc(24)] Check failed: result. 
    r0 00000000  r1 0000094c  r2 00000006  r3 f748cb7c
    r4 f748cb84  r5 f748cb34  r6 00000002  r7 0000010c
    r8 f517f90c  r9 ab645148  sl 00100019  fp ffc3c58c
    ip 00000006  sp ffc3c3e8  lr f7208f5d  pc f720b358  cpsr 400d0010

    #00 pc 00044358  /system/lib/libc.so (tgkill+12)
    #01 pc 00041f59  /system/lib/libc.so (pthread_kill+32)
    #02 pc 0001ba6f  /system/lib/libc.so (raise+10)
    #03 pc 00018c11  /system/lib/libc.so (__libc_android_abort+34)
    #04 pc 000167d0  /system/lib/libc.so (abort+4)
    #05 pc 0014540b  /data/app/com.ace.test-1/lib/arm/libflutter.so (offset 0x122000)
    #06 pc 0013a091  /data/app/com.ace.test-1/lib/arm/libflutter.so (offset 0x122000) (JNI_OnLoad+764)
    #07 pc 00250143  /system/lib/libart.so (_ZN3art9JavaVMExt17LoadNativeLibraryEP7_JNIEnvRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEP8_jobjectPS9_+1174)
    #08 pc 002c2027  /system/lib/libart.so (_ZN3artL18Runtime_nativeLoadEP7_JNIEnvP7_jclassP8_jstringP8_jobjectS5_+178)
    #09 pc 727b02c5  /data/dalvik-cache/arm/system@framework@boot.oat (offset 0x2465000)


Since only the release package has problems, it is likely that there is a problem with the confused documents. Xiaocai checked the Flutter documents that will be involved in some materials to avoid confusion, because the research on NDK is still very shallow, so only the listed scheme is provided. After that, the test results are packaged and applied normally;

#Flutter Wrapper
-dontwarn io.flutter.**
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }

Problem 2: fluterboost causes the release package to crash

Problem analysis:

After integrating fluterboost, during the test of packaging the release package, it is found that some mobile phones will crash when they move in and out twice, and the small dish will also crash, grabbing the Log to prompt the Surface to destroy the time and space pointer;

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.Surface.release()' on a null object reference
    at io.flutter.embedding.android.FlutterTextureView.disconnectSurfaceFromRenderer(SourceFile:198)
    at io.flutter.embedding.android.FlutterTextureView.detachFromRenderer(SourceFile:161)
    at com.idlefish.flutterboost.XFlutterView.detachFromFlutterEngine(SourceFile:713)
    at com.idlefish.flutterboost.containers.FlutterSplashView.onDetach(SourceFile:196)
    at com.idlefish.flutterboost.ContainerRecord.onDisappear(SourceFile:115)
    at com.idlefish.flutterboost.containers.FlutterActivityAndFragmentDelegate.onPause(SourceFile:200)
    at com.idlefish.flutterboost.containers.FlutterFragment.onPause(SourceFile:280)
    at androidx.fragment.app.Fragment.performPause(SourceFile:2879)
    at androidx.fragment.app.FragmentStateManager.pause(SourceFile:373)
    at androidx.fragment.app.FragmentManager.moveToState(SourceFile:1204)
    at androidx.fragment.app.FragmentManager.moveToState(SourceFile:1354)
    at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(SourceFile:1432)
    at androidx.fragment.app.FragmentManager.moveToState(SourceFile:1495)
    at androidx.fragment.app.FragmentManager.dispatchStateChange(SourceFile:2617)
    at androidx.fragment.app.FragmentManager.dispatchPause(SourceFile:2585)
    at androidx.fragment.app.FragmentController.dispatchPause(SourceFile:280)
    at androidx.fragment.app.FragmentActivity.onPause(SourceFile:419)
    at com.test.ace.BaseActivity.onPause(SourceFile:302)
    at com.test.ace.MainActivity.onPause(SourceFile:360)
    at android.app.Activity.performPause(Activity.java:6415)
    at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1312)
    at android.app.ActivityThread.performNewIntents(ActivityThread.java:2588)
    at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2599)
    at android.app.ActivityThread.access$1800(ActivityThread.java:153)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1447)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:5527)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)

For small dish analysis, check the source code of fluterboost, and make an error when destroying it in fluttertexture - > disconnectsurfacefromrender() - > rendersurface;

private void disconnectSurfaceFromRenderer() {
    if (flutterRenderer == null) {
      throw new IllegalStateException("disconnectSurfaceFromRenderer() should only be called when flutterRenderer is non-null.");

    renderSurface = null;

The small dish adopts Fragment mode, and the method used is newenginefregmentbuilder() mode used in the official website, which has no change operation to the life cycle;

mFragment = new FlutterFragment.NewEngineFragmentBuilder().url("url").build();

After several days of research, I didn't understand it. Later, I asked a colleague about it. I thought it was caused by version inconsistency. The current fluterboost used by Xiaocai is v1.12.13, while the local version is v1.14.6

flutter --version


I guess that fluterboost didn't adapt to the higher version of Flutter, so I'm going to try a unified version, that is, fix the current project's version of Flutter as v1.12.13+hotfix.8;

flutter version v1.12.13+hotfix.8

After clean, I tried to use the release package fearlessly, and installed it on each mobile phone. Everything was normal, and there was no flash back problem at present, which was basically caused by the inconsistency between the used fluterboost and Flutter environment;

flutter clean

Xiaocai is still short of the actual development of Flutter, and has encountered many unexpected problems. She is just in the stage of exploration and learning. If there are any mistakes, please give more guidance!

Source: little monk aze

Topics: Android Java Fragment Mobile