ReactUnity / core

React and HTML framework for Unity UI & UIToolkit
https://reactunity.github.io/
MIT License
733 stars 42 forks source link

[BUG] Error Failed to register native method `com.facebook.yoga.YogaNative.jni_YGConfigNewJNI()J` in /data/app/ #111

Closed xiaohai-huang closed 2 days ago

xiaohai-huang commented 2 months ago

My Android build crashes with the following error message.

2024/08/15 17:01:52.830 15139 15185 Error xiaohai.MiniRPG Failed to register native method com.facebook.yoga.YogaNative.jni_YGConfigNewJNI()J in /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/base.apk
2024/08/15 17:01:52.836 15139 15185 Error CRASH pid: 15139, tid: 15185, name: UnityMain  >>> com.xiaohai.MiniRPG <<<
2024/08/15 17:01:52.836 15139 15185 Error CRASH       #01 pc 0000000000038938  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libyogacore.so (BuildId: 4858824fc152829411118b818d7e59f7f9a62844)
2024/08/15 17:01:52.836 15139 15185 Error CRASH       #02 pc 0000000000038360  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libyogacore.so (BuildId: 4858824fc152829411118b818d7e59f7f9a62844)
2024/08/15 17:01:52.836 15139 15185 Error CRASH       #03 pc 0000000000038204  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libyogacore.so (BuildId: 4858824fc152829411118b818d7e59f7f9a62844)
2024/08/15 17:01:52.836 15139 15185 Error CRASH       #04 pc 0000000000051524  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libyogacore.so (__cxa_get_exception_ptr) (BuildId: 4858824fc152829411118b818d7e59f7f9a62844)
2024/08/15 17:01:52.837 15139 15185 Error CRASH       #05 pc 0000000000051498  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libyogacore.so (BuildId: 4858824fc152829411118b818d7e59f7f9a62844)
2024/08/15 17:01:52.837 15139 15185 Error CRASH       #06 pc 000000000000d134  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libyoga.so (BuildId: f7f34d30618569297f9d5abe7cbe91e553d83430)
2024/08/15 17:01:52.837 15139 15185 Error CRASH       #07 pc 000000000000d204  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libyoga.so (JNI_OnLoad+52) (BuildId: f7f34d30618569297f9d5abe7cbe91e553d83430)
2024/08/15 17:01:53.260 15236 15236 Fatal DEBUG pid: 15139, tid: 15185, name: UnityMain  >>> com.xiaohai.MiniRPG <<<
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #01 pc 0000000000038938  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libyogacore.so (BuildId: 4858824fc152829411118b818d7e59f7f9a62844)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #02 pc 0000000000038360  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libyogacore.so (BuildId: 4858824fc152829411118b818d7e59f7f9a62844)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #03 pc 0000000000038204  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libyogacore.so (BuildId: 4858824fc152829411118b818d7e59f7f9a62844)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #04 pc 0000000000051524  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libyogacore.so (BuildId: 4858824fc152829411118b818d7e59f7f9a62844)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #05 pc 0000000000051498  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libyogacore.so (__cxa_throw+128) (BuildId: 4858824fc152829411118b818d7e59f7f9a62844)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #06 pc 000000000000d134  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libyoga.so (BuildId: f7f34d30618569297f9d5abe7cbe91e553d83430)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #07 pc 000000000000d204  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libyoga.so (JNI_OnLoad+52) (BuildId: f7f34d30618569297f9d5abe7cbe91e553d83430)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #15 pc 000000000001147a  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/base.apk (com.unity3d.player.UnityPlayer.loadLibrary+2)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #21 pc 000000000075cc7c  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libunity.so (BuildId: 43bf4497c0483607)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #22 pc 000000000075b388  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libunity.so (BuildId: 43bf4497c0483607)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #23 pc 000000000075b2e8  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libunity.so (BuildId: 43bf4497c0483607)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #24 pc 0000000000774c2c  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libunity.so (BuildId: 43bf4497c0483607)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #25 pc 0000000000774a28  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libunity.so (BuildId: 43bf4497c0483607)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #26 pc 00000000005e3418  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libunity.so (BuildId: 43bf4497c0483607)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #27 pc 00000000005e38fc  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libunity.so (BuildId: 43bf4497c0483607)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #28 pc 00000000005e3b10  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libunity.so (BuildId: 43bf4497c0483607)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #29 pc 000000000052754c  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libunity.so (BuildId: 43bf4497c0483607)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #30 pc 00000000005ed2fc  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libunity.so (BuildId: 43bf4497c0483607)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #31 pc 0000000000780db4  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libunity.so (BuildId: 43bf4497c0483607)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #32 pc 0000000000781a10  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libunity.so (BuildId: 43bf4497c0483607)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #33 pc 0000000000782ca0  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/lib/arm64/libunity.so (BuildId: 43bf4497c0483607)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #36 pc 0000000000017fd8  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/base.apk (com.unity3d.player.v0.handleMessage+280)
2024/08/15 17:01:53.261 15236 15236 Fatal DEBUG       #41 pc 0000000000018948  /data/app/~~4FIby3FGUqxZt8J25q5czA==/com.xiaohai.MiniRPG-YxUEpHMB-oeFNwMCuXOmkQ==/base.apk (com.unity3d.player.x0.run+48)
2024/08/15 17:01:53.295 2985 15241 Warn ActivityTaskManager   Force finishing activity com.xiaohai.MiniRPG/com.unity3d.player.UnityPlayerActivity

The windows x64 build works without any error.

Builder Info

Unity Editor Version: 6000.0.13f1

{
    "com.reactunity.core": "0.18.4",
    "com.reactunity.quickjs": "0.17.1",

    "@reactunity/renderer": "^0.18.1",
    "@reactunity/scripts": "^0.18.3",
}

Repository

https://github.com/xiaohai-huang/mini-rpg/tree/master

xiaohai-huang commented 2 months ago

image image

Based on the git history, I guess you forgot to update the Android's yoga to the latest version (3.1.0) like the rest of the platforms.

KurtGokhan commented 2 months ago

yoga binary for Android is also on 3.1.0. The change was done after 3.1.0.

I think the issue is with Unity 6, as it was working with other versions of Unity when I tried it before.

I hadn't started updating the package for Unity 6 so far. But I will start looking into it, as there seems to be other issues related to Unity 6.

KurtGokhan commented 2 months ago

I tested this in Unity 6 and can't reproduce it.

I suspect your issue might be caused by Code Stripping. You can try to lower code stripping level. Start from "Disabled" and increase it gradually to find out where it fails.

image

xiaohai-huang commented 2 months ago

@KurtGokhan I am using IL2CPP scripting backend. It cannot be configured as disabled. I have set the Managed Stripping Level to Minimal. Can you test building the Android apk with IL2CPP scripting backend? image

xiaohai-huang commented 2 months ago

I am able to get rid of the errors by disabling Minify release in Publishing Settings. image

KurtGokhan commented 2 months ago

I just found that out too. For some reason minifying the build breaks the Yoga package. I will look into why that happens more thoroughly later. For now the minifying must be disabled.

image

I tested it in your project and that takes your APK size from 61 MB to 66 MB, which is not a huge difference. But ideally ReactUnity shouldn't break build when the Minify is turned on.

KurtGokhan commented 2 months ago

If you want to keep Minify enabled, the solution is to enable Custom Proguard File in the Project settings and add this code to the proguard file:

-keep class com.facebook.yoga.** { *; }
xiaohai-huang commented 2 months ago

I truly appreciate your assistance, @KurtGokhan Thank you for dedicating your valuable time to debugging the issue and testing my project. Your kindness means the world to me. I think I should reopen the issue as this solution needs to be documented.

KurtGokhan commented 2 days ago

Added doc here.