juicycleff / flutter-unity-view-widget

Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo
BSD 3-Clause "New" or "Revised" License
2.15k stars 525 forks source link

The app crashes and closes automatically. #757

Open alkaou opened 1 year ago

alkaou commented 1 year ago

Hello everyone. I've been stuck at this for over a week. I'm using Unity 2022.2.1f1 and the latest version of flutter. I created a small OpenCv+Unity project. I installed flutter_unity_widget 2022.2.0 for flutter and fuw 2022.2.1 for unity editor. I exported the project on android platform as it is done in the tutorial and everything went well. but now when the app launches on my android 10 "flutter run", when loading the unity scene it crashes and closes automatically. however if I build the apk with unity editor it works fine. Please I need your help. I've been looking for the solution for over a week. thank you for the good understanding.

Here is some thing i got in console

E/DartVM  (28164):   pc 0x7ad0aeb8 fp 0x88183620 sp 0x881835f8 [Unoptimized] SingleChildRenderObjectElement.update

Reloaded 0 libraries in 5 442ms (compile: 710 ms, reload: 0 ms, reassemble: 464 ms).
E/Dart    (28164): ../../third_party/dart/runtime/vm/object.cc: 4717: error: Unable to use class Library:'package:flutter_unity_widget/src/facade_controller.dart' Class: UnityWidgetController which is not loaded yet.
package:flutter_unity_widget/src/facade_controller.dart:1
E/DartVM  (28164): version=2.19.0 (stable) (Mon Jan 23 11:29:09 2023 -0800) on "android_arm"
E/DartVM  (28164): pid=28164, thread=28203, isolate_group=main(0x87d77c00), isolate=main(0x87d8bc00)
E/DartVM  (28164): os=android, arch=arm, comp=no, sim=no
E/DartVM  (28164): isolate_instructions=86d6fbe0, vm_instructions=86d6fbe0
E/DartVM  (28164):   pc 0x86e34729 fp 0x88181b60 /data/app/com.example.hello-sS_9huiXq_ZkCMJyy13PKQ==/base.apk!/lib/armeabi-v7a/libflutter.so+0x1731729
E/DartVM  (28164): -- End of DumpStackTrace
E/DartVM  (28164):   pc 0x00000000 fp 0x8818312c sp 0x00000000 [Stub] CallToRuntime
E/DartVM  (28164): pid=28164, thread=28203, isolate_group=main(0x87d77c00), isolate=main(0x87d8bc00)
E/DartVM  (28164): os=android, arch=arm, comp=no, sim=no
E/DartVM  (28164): isolate_instructions=86d6fbe0, vm_instructions=86d6fbe0
E/DartVM  (28164):   pc 0x86e34729 fp 0x88181b60 /data/app/com.example.hello-sS_9huiXq_ZkCMJyy13PKQ==/base.apk!/lib/armeabi-v7a/libflutter.so+0x1731729
E/DartVM  (28164): -- End of DumpStackTrace
E/DartVM  (28164):   pc 0x00000000 fp 0x8818312c sp 0x00000000 [Stub] CallToRuntime
E/DartVM  (28164):   pc 0x87283658 fp 0x88183154 sp 0x88183134 [Stub] OneArgCheckInlineCache
E/DartVM  (28164):   pc 0x7b85fa5c fp 0x88183170 sp 0x8818315c [Unoptimized] new StatefulElement.
E/DartVM  (28164):   pc 0x7b85f844 fp 0x88183194 sp 0x88183178 [Unoptimized] StatefulWidget.createElement
E/DartVM  (28164):   pc 0x7b827890 fp 0x881831d0 sp 0x8818319c [Unoptimized] Element.inflateWidget
E/DartVM  (28164):   pc 0x7b826934 fp 0x881831fc sp 0x881831d8 [Unoptimized] Element.updateChild
E/DartVM  (28164):   pc 0x7ad0aeb8 fp 0x8818322c sp 0x88183204 [Unoptimized] SingleChildRenderObjectElement.update
E/DartVM  (28164):   pc 0x7b8264d4 fp 0x88183254 sp 0x88183234 [Unoptimized] Element.updateChild
E/DartVM  (28164):   pc 0x7b82b594 fp 0x881832a0 sp 0x8818325c [Unoptimized] ComponentElement.performRebuild
E/DartVM  (28164):   pc 0x7b82a128 fp 0x881832d0 sp 0x881832a8 [Unoptimized] Element.rebuild
E/DartVM  (28164):   pc 0x795a5510 fp 0x881832f0 sp 0x881832d8 [Unoptimized] StatelessElement.update
E/DartVM  (28164):   pc 0x7b8264d4 fp 0x88183318 sp 0x881832f8 [Unoptimized] Element.updateChild
E/DartVM  (28164):   pc 0x7ad0aeb8 fp 0x88183348 sp 0x88183320 [Unoptimized] SingleChildRenderObjectElement.update
E/DartVM  (28164):   pc 0x7b8264d4 fp 0x88183370 sp 0x88183350 [Unoptimized] Element.updateChild
E/DartVM  (28164):   pc 0x7ad0aeb8 fp 0x881833a0 sp 0x88183378 [Unoptimized] SingleChildRenderObjectElement.update
E/DartVM  (28164):   pc 0x7b8264d4 fp 0x881833c8 sp 0x881833a8 [Unoptimized] Element.updateChild
E/DartVM  (28164):   pc 0x7b82b594 fp 0x88183414 sp 0x881833d0 [Unoptimized] ComponentElement.performRebuild
E/DartVM  (28164):   pc 0x7b862eb0 fp 0x88183430 sp 0x8818341c [Unoptimized] StatefulElement.performRebuild
E/DartVM  (28164):   pc 0x7b82a128 fp 0x88183460 sp 0x88183438 [Unoptimized] Element.rebuild
E/DartVM  (28164):   pc 0x795a126c fp 0x88183488 sp 0x88183468 [Unoptimized] StatefulElement.update
E/DartVM  (28164):   pc 0x7b8264d4 fp 0x881834b0 sp 0x88183490 [Unoptimized] Element.updateChild
E/DartVM  (28164):   pc 0x7ad0aeb8 fp 0x881834e0 sp 0x881834b8 [Unoptimized] SingleChildRenderObjectElement.update
E/DartVM  (28164):   pc 0x7b8264d4 fp 0x88183508 sp 0x881834e8 [Unoptimized] Element.updateChild
E/DartVM  (28164):   pc 0x7b82b594 fp 0x88183554 sp 0x88183510 [Unoptimized] ComponentElement.performRebuild
E/DartVM  (28164):   pc 0x7b862eb0 fp 0x88183570 sp 0x8818355c [Unoptimized] StatefulElement.performRebuild
E/DartVM  (28164):   pc 0x7b82a128 fp 0x881835a0 sp 0x88183578 [Unoptimized] Element.rebuild
E/DartVM  (28164):   pc 0x795a126c fp 0x881835c8 sp 0x881835a8 [Unoptimized] StatefulElement.update
E/DartVM  (28164):   pc 0x7b8264d4 fp 0x881835f0 sp 0x881835d0 [Unoptimized] Element.updateChild
E/DartVM  (28164):   pc 0x7ad0aeb8 fp 0x88183620 sp 0x881835f8 [Unoptimized] SingleChildRenderObjectElement.update
E/DartVM  (28164):   pc 0x7b8264d4 fp 0x88183648 sp 0x88183628 [Unoptimized] Element.updateChild
E/DartVM  (28164):   pc 0x7b82b594 fp 0x88183694 sp 0x88183650 [Unoptimized] ComponentElement.performRebuild
E/DartVM  (28164):   pc 0x7b862eb0 fp 0x881836b0 sp 0x8818369c [Unoptimized] StatefulElement.performRebuild
E/DartVM  (28164):   pc 0x7b82a128 fp 0x881836e0 sp 0x881836b8 [Unoptimized] Element.rebuild
E/DartVM  (28164):   pc 0x795a126c fp 0x88183708 sp 0x881836e8 [Unoptimized] StatefulElement.update
E/DartVM  (28164):   pc 0x7b8264d4 fp 0x88183730 sp 0x88183710 [Unoptimized] Element.updateChild
E/DartVM  (28164):   pc 0x7b82b594 fp 0x8818377c sp 0x88183738 [Unoptimized] ComponentElement.performRebuild
E/DartVM  (28164):   pc 0x7b862eb0 fp 0x88183798 sp 0x88183784 [Unoptimized] StatefulElement.performRebuild
E/DartVM  (28164):   pc 0x7ad02578 fp 0x88184890 sp 0x88184868 [Unoptimized] _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding@719399801.drawFrame
E/DartVM  (28164):   pc 0x7ad01e88 fp 0x881848ac sp 0x88184898 [Unoptimized] _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding&RendererBinding@719399801._handlePersistentFrameCallback@604452173
E/DartVM  (28164):   pc 0x7ad01da8 fp 0x881848cc sp 0x881848b4 [Unoptimized] _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding&RendererBinding@719399801._handlePersistentFrameCallback@604452173
E/DartVM  (28164):   pc 0x7ad017cc fp 0x88184920 sp 0x881848d4 [Unoptimized] _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding@719399801._invokeFrameCallback@647222615
E/DartVM  (28164):   pc 0x7ad0047c fp 0x88184960 sp 0x88184928 [Unoptimized] _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding@719399801.handleDrawFrame
E/DartVM  (28164):   pc 0x7b07f90c fp 0x8818497c sp 0x88184968 [Unoptimized] _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding@719399801.scheduleWarmUpFrame.<anonymous closure>
E/DartVM  (28164):   pc 0x7b815b60 fp 0x88184998 sp 0x88184984 [Unoptimized] Timer._createTimer@4048458.<anonymous closure>
E/DartVM  (28164):   pc 0x7b814fcc fp 0x881849e4 sp 0x881849a0 [Unoptimized] _Timer@1026248._runTimers@1026248
E/DartVM  (28164):   pc 0x7b8132e8 fp 0x88184a00 sp 0x881849ec [Unoptimized] _Timer@1026248._handleMessage@1026248
E/DartVM  (28164):   pc 0x7b812fbc fp 0x88184a18 sp 0x88184a08 [Unoptimized] _Timer@1026248._handleMessage@1026248
F/libc    (28164): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 28203 (1.ui), pid 28164 (m.example.hello)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'TECNO/H6110/TECNO-KC8:10/QP1A.190711.020/LMN-OP-210708V261:user/release-keys'
Revision: '0'
ABI: 'arm'
Timestamp: 2023-02-02 13:03:42+0000
pid: 28164, tid: 28203, name: 1.ui  >>> com.example.hello <<<
uid: 10318
signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
Abort message: '../../third_party/dart/runtime/vm/object.cc: 4717: error: Unable to use class Library:'package:flutter_unity_widget/src/facade_controller.dart' Class: UnityWidgetController which is not loaded yet.'
package:flutter_unity_widget/src/facade_controller.dart:1
    r0  00000000  r1  00006e2b  r2  00000006  r3  88181ab0
    r4  88181ac4  r5  88181aa8  r6  00006e04  r7  0000016b
    r8  88181ac0  r9  88181ab0  r10 88181ae0  r11 88181ad0
    ip  00006e2b  sp  88181a80  lr  b0c072c3  pc  b0c072d6
backtrace:
      #00 pc 0005f2d6  /apex/com.android.runtime/lib/bionic/libc.so (abort+166) (BuildId: 8b9e8a88644349ea99aee4d169971db3)
      #01 pc 0166bd0b  /data/app/com.example.hello-sS_9huiXq_ZkCMJyy13PKQ==/base.apk!libflutter.so (offset 0x7ee3000) (BuildId: 68dafb7cfd814250f6dec4fc3657008949051377)
Lost connection to device.
Reloaded 3 of 897 libraries in 7 700ms (compile: 3932 ms, reload: 627 ms, reassemble: 2777 ms).
Exited (sigterm)
timbotimbo commented 1 year ago

Can you get a project running without OpenCV or other external libraries? If so we can focus this on OpenCV.

External libraries loaded in Unity often cause a crash because something is missing at runtime in the app. They might get stripped out during the flutter build, or their dll/aar files might not be properly included by gradle.

Below is what I responed on another issue about an external library. It isn;t foolproof to detect if things get stripped out, but it is a first step to diagnose it.

A common reason for 3rd party libraries to break is because some of their code is stripped out.

For example for ARfoundation on android to work, you need to specify -keep class com.unity3d.plugin. { ; } in proguard to avoid missing libraries.

But you would have to figure out the exact name of the inworld libraries to do the same.

As a test to see if it is being stripped you can do these 2 things:

Unity player settings > code stripping > minimal disable shrinking in the flutter build with --no-shrink.

If those 2 fix the crash, you know it is stripping. Otherwise it might be related to missing permissions or files being unreadable because of compression.