f111fei/react-native-unity-view

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

itinance opened this issue · 5 comments

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 #120 and #129 might be related to this one.

Anybody found a proper solution for this?

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

Confirm that problem, can't find solution

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"

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"