tacsotai / flutter_mediapipe

BSD 3-Clause "New" or "Revised" License
23 stars 8 forks source link

App crashes in release mode #10

Closed emad-eldeen closed 2 years ago

emad-eldeen commented 3 years ago

Hi,

Thanks for the plugin. It works great in debugging apk. However, when I tried to build a release apk (flutter build apk), the app is crashing on opening the camera. I am building the example in your plugin package. I did not do any modifications on the code. I got the following errors in Logcat:

2021-08-12 21:08:09.591 2620-2693/? E/Perf: Fail to get file list co.sotai.flutter_mediapipe_example
2021-08-12 21:08:09.591 2620-2693/? E/Perf: Fail to get file list co.sotai.flutter_mediapipe_example
2021-08-12 21:08:12.594 3074-3074/? A/DEBUG: pid: 2620, tid: 2974, name: ExternalTexture  >>> co.sotai.flutter_mediapipe_example <<<
2021-08-12 21:08:13.065 3074-3074/? A/DEBUG:       #01 pc 0000000000bd557c  /data/app/co.sotai.flutter_mediapipe_example-E38YiQQIHIYt11cfZW8WPQ==/lib/arm64/libmediapipe_jni.so
2021-08-12 21:08:13.065 3074-3074/? A/DEBUG:       #02 pc 0000000000bd49c0  /data/app/co.sotai.flutter_mediapipe_example-E38YiQQIHIYt11cfZW8WPQ==/lib/arm64/libmediapipe_jni.so (google::LogMessage::SendToLog()+920)
2021-08-12 21:08:13.065 3074-3074/? A/DEBUG:       #03 pc 0000000000bd4f68  /data/app/co.sotai.flutter_mediapipe_example-E38YiQQIHIYt11cfZW8WPQ==/lib/arm64/libmediapipe_jni.so (google::LogMessage::Flush()+220)
2021-08-12 21:08:13.065 3074-3074/? A/DEBUG:       #04 pc 0000000000bd8590  /data/app/co.sotai.flutter_mediapipe_example-E38YiQQIHIYt11cfZW8WPQ==/lib/arm64/libmediapipe_jni.so (google::LogMessageFatal::~LogMessageFatal()+16)
2021-08-12 21:08:13.065 3074-3074/? A/DEBUG:       #05 pc 0000000000425a18  /data/app/co.sotai.flutter_mediapipe_example-E38YiQQIHIYt11cfZW8WPQ==/lib/arm64/libmediapipe_jni.so
2021-08-12 21:08:13.065 3074-3074/? A/DEBUG:       #06 pc 0000000000425b38  /data/app/co.sotai.flutter_mediapipe_example-E38YiQQIHIYt11cfZW8WPQ==/lib/arm64/libmediapipe_jni.so (Java_com_google_mediapipe_framework_PacketCreator_nativeCreateGpuBuffer+40)
2021-08-12 21:08:13.065 3074-3074/? A/DEBUG:       #07 pc 0000000000006cb8  /data/app/co.sotai.flutter_mediapipe_example-E38YiQQIHIYt11cfZW8WPQ==/oat/arm64/base.odex (art_jni_trampoline+184)
2021-08-12 21:08:13.065 3074-3074/? A/DEBUG:       #14 pc 0000000000053740  /data/app/co.sotai.flutter_mediapipe_example-E38YiQQIHIYt11cfZW8WPQ==/oat/arm64/base.vdex (com.google.mediapipe.framework.PacketCreator.a+40)
2021-08-12 21:08:13.065 3074-3074/? A/DEBUG:       #17 pc 0000000000052abc  /data/app/co.sotai.flutter_mediapipe_example-E38YiQQIHIYt11cfZW8WPQ==/oat/arm64/base.vdex (c.a.b.a.m.a+188)
2021-08-12 21:08:13.065 3074-3074/? A/DEBUG:       #20 pc 000000000005229c  /data/app/co.sotai.flutter_mediapipe_example-E38YiQQIHIYt11cfZW8WPQ==/oat/arm64/base.vdex (c.a.b.a.l$a.o+188)
2021-08-12 21:08:13.065 3074-3074/? A/DEBUG:       #23 pc 0000000000052080  /data/app/co.sotai.flutter_mediapipe_example-E38YiQQIHIYt11cfZW8WPQ==/oat/arm64/base.vdex (c.a.b.a.l$a.j)
2021-08-12 21:08:13.065 3074-3074/? A/DEBUG:       #26 pc 0000000000052068  /data/app/co.sotai.flutter_mediapipe_example-E38YiQQIHIYt11cfZW8WPQ==/oat/arm64/base.vdex (c.a.b.a.l$a.k)
2021-08-12 21:08:13.065 3074-3074/? A/DEBUG:       #29 pc 00000000000516fc  /data/app/co.sotai.flutter_mediapipe_example-E38YiQQIHIYt11cfZW8WPQ==/oat/arm64/base.vdex (c.a.b.a.i.run+8)
2021-08-12 21:08:13.065 3074-3074/? A/DEBUG:       #41 pc 0000000000054946  /data/app/co.sotai.flutter_mediapipe_example-E38YiQQIHIYt11cfZW8WPQ==/oat/arm64/base.vdex (c.a.b.b.c.run+106)
2021-08-12 21:08:13.858 1624-2106/? E/InputDispatcher: channel '7661bd9 Sys2030:co.sotai.flutter_mediapipe_example/co.sotai.flutter_mediapipe_example.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
2021-08-12 21:08:13.858 1624-2106/? E/InputDispatcher: channel 'a37fbc co.sotai.flutter_mediapipe_example/co.sotai.flutter_mediapipe_example.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
2021-08-12 21:08:13.900 894-894/? E/CompositionEngine: Error when queueing buffer for display [flutter-vd]: -32
2021-08-12 21:08:13.909 1624-3299/? E/InputDispatcher: Window handle Window{7661bd9 u0 Sys2030:co.sotai.flutter_mediapipe_example/co.sotai.flutter_mediapipe_example.MainActivity} has no registered input channel
2021-08-12 21:08:13.918 1624-4397/? E/InputDispatcher: Window handle Window{7661bd9 u0 Sys2030:co.sotai.flutter_mediapipe_example/co.sotai.flutter_mediapipe_example.MainActivity} has no registered input channel
tacsotai commented 3 years ago

Thank you for your using and report. But nowadays, little bit busy. Please wait a couple weeks. After that, I will check it.

tacsotai commented 3 years ago

Hi @Emad-Eldeen

Thank you for your report. You are right. It seems to not refer JNI lib, Now I struggling to refer it.

flutter_mediapipe/example/android/app/build.gradle

    externalNativeBuild {
        ndkBuild {
            path '../../../android/src/main/jniLibs/arm64-v8a/libopencv_java3.so', '../../../android/src/main/jniLibs/arm64-v8a/libmediapipe_jni.so'
        }
    }

But, in order to do that, release key from google is required, it seems.

* Where:                                                                
Build file '/Users/hoge/flutter_mediapipe/example/android/app/build.gradle' line: 27

* What went wrong:                                                      
A problem occurred evaluating project ':app'.                           
> No signature of method: build_9vdixiby72husarqd7bfv6pf9.android() is applicable for argument types: (build_9vdixiby72husarqd7bfv6pf9$_run_closure2) values: [build_9vdixiby72husarqd7bfv6pf9$_run_closure2@2dd56c8c]

It needs much more time to solve it. Thank you for your patience.

tacsotai commented 3 years ago

If there is any other way to fix, please let me know. Actually, it is my first time to make Smartphone application.

tacsotai commented 3 years ago

@Emad-Eldeen

I am keeping to investigate it. I confirmed app-release.apk contains JNI libs with extracting file. The difference of size between app-debub.apk and app-release.apk is kernel_blob.bin size basically.

So, I think the reason is the permission for release. https://flutter.dev/docs/deployment/android

   signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }

Currently, I don't want to release this sample for Android Play. If you tried other example of the app-release.apk, please let me know.

Thanks, tac.

emad-eldeen commented 3 years ago

Hello Tac, Thanks for the hint. I will check that and in case I was able to solve it, I will create a pull request.

BR

emad-eldeen commented 2 years ago

I was finally able to fix this issue. The issue is coming from R8 shrinking and minimizing in Gradle. It seems that it is detecting some mediapipe code as not needed and removing it for some reason. The issue was fixed by setting the following config in build.grade file: image

tacsotai commented 2 years ago

Thank you for your help. I will check it.