f111fei / react-native-unity-view

Show an unity view in react native
MIT License
401 stars 102 forks source link

Crashes on Android due to error "libmain.so not found" with RN > 0.60 #142

Closed itinance closed 4 years ago

itinance commented 4 years ago

While everything works fine with React Native below any version under 0.60, on Android the application will crash upon activating the UnityView with RN > 0.60.

The final error happens because of a "libmain.so" could not be loaded:

E Unity   : Failed to load 'libmain.so', the application will terminate.
D AndroidRuntime: Shutting down VM
E AndroidRuntime: FATAL EXCEPTION: main
E AndroidRuntime: Process: com.rnunitydemo, PID: 16887
E AndroidRuntime: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.rnunitydemo-bKGyotdcwjVnBxuR9zLE4Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.rnunitydemo-bKGyotdcwjVnBxuR9zLE4Q==/lib/arm64, /data/app/com.rnunitydemo-bKGyotdcwjVnBxuR9zLE4Q==/base.apk!/lib/arm64-v8a, /system/lib64, /product/lib64]]] couldn't find "libmain.so"

According to a crash-report in the official Unity-Forum, we took care to use the same settings in both build.gradle for ndk-abiFilter:

android {
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        ndk {
            abiFilters 'armeabi-v7a', 'x86'
        }
        multiDexEnabled true
        versionCode 1
        versionName '0.1'
    }
}

but it won't fix the issue. There is a big chance that the issues https://github.com/f111fei/react-native-unity-view/issues/120 and https://github.com/f111fei/react-native-unity-view/issues/129 might be related to this one.

Anybody found a proper solution for this?

itinance commented 4 years ago

Apparently this issue is not only related to React Native and its gradle-files, but a common issue nowadays according to StackOverflow, like this: https://stackoverflow.com/questions/58751549/unable-to-load-libmain-so-in-android-studio-and-unity-as-library

itinance commented 4 years ago

https://stackoverflow.com/questions/58877735/how-to-solve-libmain-so-not-found-while-using-unity-as-a-library-in-android-ap

Villar74 commented 4 years ago

Confirm that problem, can't find solution

itinance commented 4 years ago

Found it. Bevor building for Android, we need to adjust some settings in "Player Settings" in order to make ARM64 Bit available:

Screenshot 2019-11-21 16 12 15

If you run into an Error like "NDK not found", ensure that Unity has downloaded and installed its own copy of NDK:

Screenshot 2019-11-21 17 24 43

Having all this in mind will enable us to link against these libraries without failing to find "libmain.so"

KainanSu commented 2 years ago

It works, thanks

Found it. Bevor building for Android, we need to adjust some settings in "Player Settings" in order to make ARM64 Bit available:

  • Switching "Scripting Backend" from Mono to ILCPP, which enables us to:
  • Select "ARM64" under Target Architectures
Screenshot 2019-11-21 16 12 15

If you run into an Error like "NDK not found", ensure that Unity has downloaded and installed its own copy of NDK:

Screenshot 2019-11-21 17 24 43

Having all this in mind will enable us to link against these libraries without failing to find "libmain.so"