Error when linking "aar" with native dependencies on Android: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol __emutls_get_address referenced by .../lib/arm64/libfolly_runtime.so
Description
I had an error when integrating a third-party Android .aar to my project.
With newArchEnabled=false the project is compiling successfully but crashing on start (even in debug mode).
With newArchEnabled=true the project is compiling and opening successfully, but some parts are not working due to incompatibility with other libraries, like react-navigation.
So we can't use the newArchEnabled=true right now.
Primarily I have tried on a RN 0.72.10 project, but to simulate the problem in a clean environment, I have created a new project with RN 0.73.4 and just linked the .aab:
dependencies {
implementation (files("libs/my-file.aar"))
}
The error with newArchEnabled=false:
E FATAL EXCEPTION: main
Process: com.rncanoasdk, PID: 27273
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__emutls_get_address" referenced by "/data/app/~~uaBbfX-mIx0xfhEaF7JQtQ==/com.rncanoasdk-8i3wtPg1PWkRj3Nnps2D5w==/lib/arm64/libfolly_runtime.so"...
at java.lang.Runtime.loadLibrary0(Runtime.java:1082)
at java.lang.Runtime.loadLibrary0(Runtime.java:1003)
at java.lang.System.loadLibrary(System.java:1661)
at com.facebook.soloader.nativeloader.SystemDelegate.loadLibrary(SystemDelegate.java:24)
at com.facebook.soloader.nativeloader.NativeLoader.loadLibrary(NativeLoader.java:52)
at com.facebook.soloader.nativeloader.NativeLoader.loadLibrary(NativeLoader.java:30)
at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:869)
at com.facebook.hermes.reactexecutor.HermesExecutor.loadLibrary(HermesExecutor.java:26)
at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:20)
at com.facebook.react.ReactInstanceManagerBuilder.getDefaultJSExecutorFactory(ReactInstanceManagerBuilder.java:384)
at com.facebook.react.ReactInstanceManagerBuilder.build(ReactInstanceManagerBuilder.java:326)
at com.facebook.react.ReactNativeHost.createReactInstanceManager(ReactNativeHost.java:98)
at com.facebook.react.ReactNativeHost.getReactInstanceManager(ReactNativeHost.java:43)
at com.facebook.react.ReactDelegate.loadApp(ReactDelegate.java:173)
at com.facebook.react.ReactActivityDelegate.loadApp(ReactActivityDelegate.java:123)
at com.facebook.react.ReactActivityDelegate.onCreate(ReactActivityDelegate.java:118)
at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:46)
at android.app.Activity.performCreate(Activity.java:8944)
at android.app.Activity.performCreate(Activity.java:8913)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1456)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4146)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4322)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2685)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:8893)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Inspecting the .aar I found these jni libraries:
I also have tried to add some pickFirst instructions, with no success:
packagingOptions {
pickFirst 'lib/x86_64/libopencv_java4.so'
pickFirst 'lib/x86_64/libchilkat.so'
pickFirst 'lib/x86_64/libtensorflowlite_jni.so'
pickFirst 'lib/x86_64/libc++_shared.so'
pickFirst 'lib/x86_64/libcanoanative.so'
pickFirst 'lib/x86_64/libsincrSeg.so'
pickFirst 'lib/x86/libopencv_java4.so'
pickFirst 'lib/x86/libchilkat.so'
pickFirst 'lib/x86/libtensorflowlite_jni.so'
pickFirst 'lib/x86/libc++_shared.so'
pickFirst 'lib/x86/libcanoanative.so'
pickFirst 'lib/x86/libsincrSeg.so'
pickFirst 'lib/arm64-v8a/libopencv_java4.so'
pickFirst 'lib/arm64-v8a/libchilkat.so'
pickFirst 'lib/arm64-v8a/libtensorflowlite_jni.so'
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/arm64-v8a/libcanoanative.so'
pickFirst 'lib/arm64-v8a/libsincrSeg.so'
pickFirst 'lib/armeabi-v7a/libopencv_java4.so'
pickFirst 'lib/armeabi-v7a/libchilkat.so'
pickFirst 'lib/armeabi-v7a/libtensorflowlite_jni.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libcanoanative.so'
pickFirst 'lib/armeabi-v7a/libsincrSeg.so'
}
And:
packagingOptions {
pickFirst '**/libopencv_java4.so'
pickFirst '**/libchilkat.so'
pickFirst '**/libtensorflowlite_jni.so'
pickFirst '**/libc++_shared.so'
pickFirst '**/libcanoanative.so'
pickFirst '**/libsincrSeg.so'
}
The most strange part comes now, if we install the aar as a local maven repository, everything works fine:
mvn install:install-file -Dfile="path-to-file.aar" \
-DgroupId=com.package \
-DartifactId=sdk-name \
-Dversion=1.0.0 \
-Dpackaging=aar
And then, in android/app/build.gradle:
-implementation (files("libs/my-file.aar"))
+implementation group: 'com.package', name: 'sdk-name', version: '1.0.0', changing: true
So the question is:
Why with newArchEnabled=true works and newArchEnabled=false crash when linking the aar directly?
And why with a maven local repository also works with newArchEnabled=false, what is different?
Steps to reproduce
Unfortunately, I can't provide the aar file to simulate the problem, but in this issue we have others with the same problem with the Tuya aar.
https://github.com/facebook/react-native/issues/37890
React Native Version
0.73.4
Affected Platforms
Runtime - Android
Areas
Bridgeless - The New Initialization Flow
Output of npx react-native info
info Fetching system and libraries information...
System:
OS: macOS 13.5.1
CPU: (8) arm64 Apple M1
Memory: 112.36 MB / 8.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 18.17.1
path: ~/.nvm/versions/node/v18.17.1/bin/node
Yarn:
version: 1.22.19
path: ~/.nvm/versions/node/v18.17.1/bin/yarn
npm:
version: 9.6.7
path: ~/.nvm/versions/node/v18.17.1/bin/npm
Watchman:
version: 2024.01.22.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.12.0
path: /Users/douglas.junior/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 23.2
- iOS 17.2
- macOS 14.2
- tvOS 17.2
- visionOS 1.0
- watchOS 10.2
Android SDK:
API Levels:
- "31"
- "32"
- "33"
- "34"
Build Tools:
- 30.0.2
- 30.0.3
- 33.0.0
- 34.0.0
Android NDK: Not Found
IDEs:
Android Studio: 2023.1 AI-231.9392.1.2311.11330709
Xcode:
version: 15.2/15C500b
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.9
path: /usr/bin/javac
Ruby:
version: 3.1.1
path: /Users/douglas.junior/.rbenv/shims/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.73.4
wanted: 0.73.4
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: Not found
newArchEnabled: false
Stacktrace or Logs
E FATAL EXCEPTION: main
Process: com.rncanoasdk, PID: 27273
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__emutls_get_address" referenced by "/data/app/~~uaBbfX-mIx0xfhEaF7JQtQ==/com.rncanoasdk-8i3wtPg1PWkRj3Nnps2D5w==/lib/arm64/libfolly_runtime.so"...
at java.lang.Runtime.loadLibrary0(Runtime.java:1082)
at java.lang.Runtime.loadLibrary0(Runtime.java:1003)
at java.lang.System.loadLibrary(System.java:1661)
at com.facebook.soloader.nativeloader.SystemDelegate.loadLibrary(SystemDelegate.java:24)
at com.facebook.soloader.nativeloader.NativeLoader.loadLibrary(NativeLoader.java:52)
at com.facebook.soloader.nativeloader.NativeLoader.loadLibrary(NativeLoader.java:30)
at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:869)
at com.facebook.hermes.reactexecutor.HermesExecutor.loadLibrary(HermesExecutor.java:26)
at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:20)
at com.facebook.react.ReactInstanceManagerBuilder.getDefaultJSExecutorFactory(ReactInstanceManagerBuilder.java:384)
at com.facebook.react.ReactInstanceManagerBuilder.build(ReactInstanceManagerBuilder.java:326)
at com.facebook.react.ReactNativeHost.createReactInstanceManager(ReactNativeHost.java:98)
at com.facebook.react.ReactNativeHost.getReactInstanceManager(ReactNativeHost.java:43)
at com.facebook.react.ReactDelegate.loadApp(ReactDelegate.java:173)
at com.facebook.react.ReactActivityDelegate.loadApp(ReactActivityDelegate.java:123)
at com.facebook.react.ReactActivityDelegate.onCreate(ReactActivityDelegate.java:118)
at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:46)
at android.app.Activity.performCreate(Activity.java:8944)
at android.app.Activity.performCreate(Activity.java:8913)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1456)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4146)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4322)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2685)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:8893)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Reproducer
https://github.com/react-navigation/react-navigation
(sorry but I can't provide the aar file 😓)
Screenshots and Videos
No response
| :warning: | Missing Reproducible Example |
|---|---|
| :information_source: | We could not detect a reproducible example in your issue report. Please provide either:
|
Sorry but I can't provide the aar file 😓 to reproduce the problem.
I had an error when integrating a third-party Android
.aarto my project. WithnewArchEnabled=falsethe project is compiling successfully but crashing on start (even in debug mode).
Ok so there are a number of problems here.
I'd say let's focus on having you building with the .aar correctly on Old Arch.
For the New Architecture problem, please open a separate issue explaining what's the problem you're having with -navigation.
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__emutls_get_address" referenced by "/data/app/~~uaBbfX-mIx0xfhEaF7JQtQ==/com.rncanoasdk-8i3wtPg1PWkRj3Nnps2D5w==/lib/arm64/libfolly_runtime.so"...
This happens because the .aar you're importing has native libraries built with older versions of the NDK. You should make sure the library is built with the same NDK version as React Native (NDK 25.1.8937393 for RN 0.73.x).
Do you build the .aar by yourself or you get it from a 3rd party?
Hi @cortinico, thank you very much for the feedback.
This happens because the .aar you're importing has native libraries built with older versions of the NDK. You should make sure the library is built with the same NDK version as React Native (NDK 25.1.8937393 for RN 0.73.x).
Yeah, reading about the error I found some issues related to it, so I tried to downgrade the NDK to the one used in RN 0.70 (which the aar works with the Old Arch), but no success either.
Do you build the .aar by yourself or you get it from a 3rd party?
It's a 3rd party which we don't have access to the source code.
So, if the problem is, in fact, the NDK, why when we use maven local or New Arch to link the aar the problem don't happen? In all the cases, the NDK still the same.
Yeah, reading about the error I found some issues related to it, so I tried to downgrade the NDK to the one used in RN 0.70 (which the aar works with the Old Arch), but no success either.
The problem is the NDK used to build the library. That needs to be aligned with the one you use to build your App.
why when we use maven local
Can you clarify this?
Can you clarify this?
Using RN 0.73 and Old Arch it's possible to use the problematic aar file by linking it via maven local repository.
Just installing the aar using mvn command:
mvn install:install-file -Dfile="path-to-file.aar" \
-DgroupId=com.package \
-DartifactId=sdk-name \
-Dversion=1.0.0 \
-Dpackaging=aar
And then, adding the implemetation on the android/app/build.gradle like this:
implementation group: 'com.package', name: 'sdk-name', version: '1.0.0', changing: true
Using RN 0.73 and Old Arch it's possible to use the problematic aar file by linking it via maven local repository.
I don't know why this is happening, as the consumed file is the same. I believe there is something going on with your environemtn
I don't think the problem is in my environment because here we work with a dozen of other RN apps, and the problem is easy reproducible on other team member PC/Mac too.
Just for summarize what work or not:
| Scenario | Works? |
|---|---|
New RN 0.73 Old Arch app linking aar directly |
No |
| New RN 0.73 Old Arch app linking with maven | Yes |
New RN 0.73 New Arch app linking aar directly |
Yes |
New native Android app linking aar directly |
Yes |
| New native Android app linking with maven | Yes |
Sadly without a reproducer of any sort this is extremely hard for us to investigate.
Yes, I know, I apologize for that.
Unfortunately, I do not have authorization from the supplier to provide a copy of the aar.
Thanks for the help, closing the issue for now.
No need to rebuild third-party .aar or .so, just patch:
cd tools/android-sdk/ndk
mv ./21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so ./21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/origin_libc++_shared.so
cp ./23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so ./21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/
as described in Patch to fix __emutls_get_address crash on Android