Comments (9)
@yMayanand, @akashraj9828, we identified the culprit! This issue is caused by conflicting fbjni
versions from React Native and PyTorch Android.
- React Native
0.64.2
bundles fbjni0.0.2
- PyTorch Android
1.10.0
bundles fbjni0.0.5-SNAPSHOT
The PyTorch Android JNI needs a symbol that is available starting at fbjni 0.0.3
(i.e., _ZN8facebook3jni12jtype_traitsIiE11kDescriptorE
).
If there are multiple shared objects with the same name (e.g., libfbjni.so
), Gradle is set to pick the first file for the apk (see gradle.build
and packingOptions
with pickFirst
). The Gradle assemble process on macOS and linux seem to differ in which file for fbjni
(or libfbjni.so
) gets picked over another. On macOS, the assemble step picks the fbjni version from PyTorch Android (i.e., 0.0.5-SNAPSHOT
). On linux, it picks the fbjni version from React Native (i.e., 0.0.2
that doesn't have the symbol _ZN8facebook3jni12jtype_traitsIiE11kDescriptorE
).
In consequence, installing the apk built on linux will result in the UnsatisfiedLinkError
reported in this issue.
Fortunately, there are two options to solve this. Option 1 is upgrading React Native to 0.65.0
which upgraded to fbjni 0.0.3
(preferred solution). If you can't upgrade React Native, then option 2 is building the apk and then repackage with the fbjni libs from PyTorch Android. The instructions for both options are below. We will provide a forward fix in the next version.
- Upgrade the React Native version to 0.65.1 (which has fbjni 0.0.3, see React Native
0.65.0
CHANGELOG.md)
- Use the React Native Upgrader Tool to see what changes need to be applied (link to upgrade instructions from React Native 0.64.2 to 0.65.1)
- Upgrade Gradle from
6.7
to6.9
, which means changeandroid/gradle/wrapper/gradle-wrapper.properties
to the following:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
- Build the apk on linux, unpack contents, change
libfbjni.so
, repackage apk
- Install
apktool
from the original website (follow their install instructions as the version installed viaapt install apktool
will fail with an error on bundle)
You can put the following commands in a script/bash file fixapk.sh
in the project root folder. Make it executable with chmod +x fixapk.sh
and then run ./fixapk
and wait ☕. The result will be a file app-release-fixed.apk
which can be installed in the emulator or on a device with adb install app-release-fixed.apk
.
#!/bin/bash
echo "Building release apk"
(cd android && ./gradlew assembleRelease)
echo "Unzipping apk to temporary directory"
apktool d -f -r -s android/app/build/outputs/apk/release/app-release.apk
echo "Replacing fbjni 0.0.2 with newer fbjni from PyTorch Android"
cp node_modules/react-native-pytorch-core/android/build/pytorch_android_lite-1.10.0.aar/jni/armeabi-v7a/libfbjni.so app-release/lib/armeabi-v7a
cp node_modules/react-native-pytorch-core/android/build/pytorch_android_lite-1.10.0.aar/jni/x86/libfbjni.so app-release/lib/x86
cp node_modules/react-native-pytorch-core/android/build/pytorch_android_lite-1.10.0.aar/jni/arm64-v8a/libfbjni.so app-release/lib/arm64-v8a
cp node_modules/react-native-pytorch-core/android/build/pytorch_android_lite-1.10.0.aar/jni/x86_64/libfbjni.so app-release/lib/x86_64
echo "Packaging changed apk content to fixed apk"
apktool b app-release -o app-release-temp.apk
echo "Signing apk with debug signing config"
# [Android documentation about debug signing config](https://github.com/pytorch/live/blob/v0.1.3/react-native-template-pytorch-live/template/android/app/build.gradle#L170-L175)
jarsigner -verbose -keystore android/app/debug.keystore -storepass android -keypass android app-release-temp.apk androiddebugkey
echo "Aligning signed apk"
# https://developer.android.com/studio/build/building-cmdline
zipalign -v -p 4 app-release-temp.apk app-release-fixed.apk
Help Wanted
Please reach out to us or comment here if you have an idea how to fix this already during the Gradle assemble step!
from playtorch.
Hi @yMayanand,
Would you please attach a crash log from the Metro logs and from adb logcat
? I expect this would contain a stack trace and help to pinpoint the root issue.
Thanks!
from playtorch.
logs.txt
@chrisklaiber as you said i had attached the adb logcat to the app and got the logs from it.
I read some logs and from them i guess the following things maybe responsible for crash.
01-26 09:56:50.426 2591 2614 E AndroidRuntime: FATAL EXCEPTION: Thread-2
01-26 09:56:50.426 2591 2614 E AndroidRuntime: Process: com.huawei.android.thememanager, PID: 2591
01-26 09:56:50.426 2591 2614 E AndroidRuntime: java.lang.IllegalStateException: SharedPreferences in credential encrypted storage are not available until after user is unlocked
01-26 09:56:50.426 2591 2614 E AndroidRuntime: at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:451)
01-26 09:56:50.426 2591 2614 E AndroidRuntime: at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:436)
01-26 09:56:50.426 2591 2614 E AndroidRuntime: at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:174)
01-26 09:56:50.426 2591 2614 E AndroidRuntime: at com.huawei.hms.framework.qoes.l.<init>(:2)
01-26 09:56:50.426 2591 2614 E AndroidRuntime: at com.huawei.hms.framework.qoes.HmsQoEApiManager.b(:3)
01-26 09:56:50.426 2591 2614 E AndroidRuntime: at com.huawei.hms.framework.qoes.f.run(Unknown Source:4)
01-26 09:56:50.426 2591 2614 E AndroidRuntime: at java.lang.Thread.run(Thread.java:784)
01-27 22:53:54.705 26818 26864 E AndroidRuntime: FATAL EXCEPTION: create_react_context
01-27 22:53:54.705 26818 26864 E AndroidRuntime: Process: org.pytorch.live.example, PID: 26818
01-27 22:53:54.705 26818 26864 E AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN8facebook3jni12jtype_traitsIiE11kDescriptorE" referenced by "/data/app/org.pytorch.live.example-dqK3XWctaOIm3C1yDVDouw==/base.apk!/lib/arm64-v8a/libpytorch_jni_lite.so"...
01-27 22:53:54.705 26818 26864 E AndroidRuntime: at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
01-27 22:53:54.705 26818 26864 E AndroidRuntime: at java.lang.System.loadLibrary(System.java:1672)
01-27 22:53:54.705 26818 26864 E AndroidRuntime: at org.pytorch.rn.core.jsi.PyTorchCoreJSIModule.<clinit>(PyTorchCoreJSIModule.java:25)
01-27 22:53:54.705 26818 26864 E AndroidRuntime: at org.pytorch.rn.core.PyTorchCorePackage.createNativeModules(PyTorchCorePackage.java:30)
01-27 22:53:54.705 26818 26864 E AndroidRuntime: at com.facebook.react.ReactPackageHelper.getNativeModuleIterator(ReactPackageHelper.java:42)
01-27 22:53:54.705 26818 26864 E AndroidRuntime: at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:42)
01-27 22:53:54.705 26818 26864 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1347)
01-27 22:53:54.705 26818 26864 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1318)
01-27 22:53:54.705 26818 26864 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1240)
01-27 22:53:54.705 26818 26864 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.access$1100(ReactInstanceManager.java:131)
01-27 22:53:54.705 26818 26864 E AndroidRuntime: at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:1023)
01-27 22:53:54.705 26818 26864 E AndroidRuntime: at java.lang.Thread.run(Thread.java:784)
01-27 22:53:57.995 26902 26945 E AndroidRuntime: FATAL EXCEPTION: create_react_context
01-27 22:53:57.995 26902 26945 E AndroidRuntime: Process: org.pytorch.live.example, PID: 26902
01-27 22:53:57.995 26902 26945 E AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN8facebook3jni12jtype_traitsIiE11kDescriptorE" referenced by "/data/app/org.pytorch.live.example-dqK3XWctaOIm3C1yDVDouw==/base.apk!/lib/arm64-v8a/libpytorch_jni_lite.so"...
01-27 22:53:57.995 26902 26945 E AndroidRuntime: at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
01-27 22:53:57.995 26902 26945 E AndroidRuntime: at java.lang.System.loadLibrary(System.java:1672)
01-27 22:53:57.995 26902 26945 E AndroidRuntime: at org.pytorch.rn.core.jsi.PyTorchCoreJSIModule.<clinit>(PyTorchCoreJSIModule.java:25)
01-27 22:53:57.995 26902 26945 E AndroidRuntime: at org.pytorch.rn.core.PyTorchCorePackage.createNativeModules(PyTorchCorePackage.java:30)
01-27 22:53:57.995 26902 26945 E AndroidRuntime: at com.facebook.react.ReactPackageHelper.getNativeModuleIterator(ReactPackageHelper.java:42)
01-27 22:53:57.995 26902 26945 E AndroidRuntime: at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:42)
01-27 22:53:57.995 26902 26945 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1347)
01-27 22:53:57.995 26902 26945 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1318)
01-27 22:53:57.995 26902 26945 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1240)
01-27 22:53:57.995 26902 26945 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.access$1100(ReactInstanceManager.java:131)
01-27 22:53:57.995 26902 26945 E AndroidRuntime: at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:1023)
01-27 22:53:57.995 26902 26945 E AndroidRuntime: at java.lang.Thread.run(Thread.java:784)
01-28 09:25:00.152 10716 10768 F libc : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x70109e7b98 in tid 10768 (bgExecutor #0), pid 10716 (android.vending)
01-28 09:25:00.374 16408 16408 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ```
I hope this helps resolving the issue.
from playtorch.
@yMayanand, PyTorch Live supports Android 10+ (see README)
PyTorch Live apps may target Android 10.0 (API 21) and iOS 12.0 or newer.
It seems that the shared libraries for PyTorch Android (libpytorch_jni_lite
) are missing. Can you check if the *.so
are in the app-debug.apk
?
- Go to
cd <PROJECT>/android/app/build/outputs/apk/debug
unzip app-debug.apk
- Check if the lib folder for your device's architecture has the
*.so
files- e.g.,
cd <PROJECT>/android/app/build/outputs/apk/debug/lib/x86
- e.g.,
The project is currently building for arm64-v8a
, armeabi-v7a
, x86
, and x86_64
.
from playtorch.
@raedle My phones architecture is arm64-v8a
and i had checked the folder
<PROJECT>/android/app/build/outputs/apk/debug/lib/arm64-v8a
for *.so
files. It has all the *.so
files and i also looked for libpytorch_jni_lite
file it had that too.
from playtorch.
@yMayanand, does the app also crash on a device Android 10.0+ (API 21+)? If yes, would you be able to share the project in a repo?
from playtorch.
@raedle I am running on Android 11 and it crashes for me as well...
This is happening for me even in example project (https://pytorch.org/live/docs/tutorials/image-classification/)
I have not added a single line of code from my side
Here's the logcat of crash
03-29 16:14:56.279 18407 18407 W unknown:ReactNative: Packager connection already open, nooping.
03-29 16:14:56.315 1532 1709 I ActivityTaskManager: Displayed org.pytorch.live.example/.MainActivity: +739ms
03-29 16:14:56.320 1532 1692 D EventSequenceValidator: dec AccIntentStartedEvents to 1
03-29 16:14:56.508 18407 18460 D SoLoader: About to load: libhermes.so
03-29 16:14:56.508 18407 18460 D SoLoader: libhermes.so not found on /data/user/0/org.pytorch.live.example/lib-main
03-29 16:14:56.508 18407 18460 D SoLoader: libhermes.so found on /data/app/~~oQy-oOr9y0FDzYve7IgTEw==/org.pytorch.live.example-voXhERWr7pFbLgSsuzABsw==/lib/arm64
03-29 16:14:56.508 18407 18460 D SoLoader: Not resolving dependencies for libhermes.so
03-29 16:14:56.517 18407 18460 D SoLoader: Loaded: libhermes.so
03-29 16:14:56.517 18407 18460 D SoLoader: About to load: libhermes-executor-debug.so
03-29 16:14:56.518 18407 18460 D SoLoader: libhermes-executor-debug.so not found on /data/user/0/org.pytorch.live.example/lib-main
03-29 16:14:56.518 18407 18460 D SoLoader: libhermes-executor-debug.so found on /data/app/~~oQy-oOr9y0FDzYve7IgTEw==/org.pytorch.live.example-voXhERWr7pFbLgSsuzABsw==/lib/arm64
03-29 16:14:56.518 18407 18460 D SoLoader: Not resolving dependencies for libhermes-executor-debug.so
03-29 16:14:56.547 18407 18460 D SoLoader: Loaded: libhermes-executor-debug.so
03-29 16:14:56.568 18407 18460 E AndroidRuntime: FATAL EXCEPTION: create_react_context
03-29 16:14:56.568 18407 18460 E AndroidRuntime: Process: org.pytorch.live.example, PID: 18407
03-29 16:14:56.568 18407 18460 E AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN8facebook3jni12jtype_traitsIiE11kDescriptorE" referenced by "/data/app/~~oQy-oOr9y0FDzYve7IgTEw==/org.pytorch.live.example-voXhERWr7pFbLgSsuzABsw==/lib/arm64/libpytorch_jni_lite.so"...
03-29 16:14:56.568 18407 18460 E AndroidRuntime: at java.lang.Runtime.loadLibrary0(Runtime.java:1087)
03-29 16:14:56.568 18407 18460 E AndroidRuntime: at java.lang.Runtime.loadLibrary0(Runtime.java:1008)
03-29 16:14:56.568 18407 18460 E AndroidRuntime: at java.lang.System.loadLibrary(System.java:1664)
03-29 16:14:56.568 18407 18460 E AndroidRuntime: at org.pytorch.rn.core.jsi.PyTorchCoreJSIModule.<clinit>(PyTorchCoreJSIModule.java:25)
03-29 16:14:56.568 18407 18460 E AndroidRuntime: at org.pytorch.rn.core.PyTorchCorePackage.createNativeModules(PyTorchCorePackage.java:30)
03-29 16:14:56.568 18407 18460 E AndroidRuntime: at com.facebook.react.ReactPackageHelper.getNativeModuleIterator(ReactPackageHelper.java:42)
03-29 16:14:56.568 18407 18460 E AndroidRuntime: at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:42)
03-29 16:14:56.568 18407 18460 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1347)
03-29 16:14:56.568 18407 18460 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1318)
03-29 16:14:56.568 18407 18460 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1240)
03-29 16:14:56.568 18407 18460 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.access$1100(ReactInstanceManager.java:131)
03-29 16:14:56.568 18407 18460 E AndroidRuntime: at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:1023)
03-29 16:14:56.568 18407 18460 E AndroidRuntime: at java.lang.Thread.run(Thread.java:923)
03-29 16:14:56.571 1532 18461 I DropBoxManagerService: add tag=data_app_crash isTagEnabled=true flags=0x2
03-29 16:14:56.571 1532 8668 W ActivityTaskManager: Force finishing activity org.pytorch.live.example/.MainActivity
03-29 16:14:56.574 1532 18461 W DropBoxManagerService: Dropping: data_app_crash (1526 > 0 bytes)
03-29 16:14:56.578 18407 18460 I Process : Sending signal. PID: 18407 SIG: 9
03-29 16:14:56.580 1532 1710 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.stats.service.DropBoxEntryAddedReceiver
03-29 16:14:56.581 1532 1710 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver
03-29 16:14:56.630 1532 3795 I ActivityManager: Process org.pytorch.live.example (pid 18407) has died: prcp TOP
Just to be sure i confirmed if i have libpytorch_jni_lite.so
file bundled
and it is present in the installed app
from playtorch.
I have tried first option but the problem was not solved, i am eagerly waiting for next version
so that problem would get solved implicitly.
from playtorch.
The PlayTorch 0.2.0 series introduced new JavaScript interfaces to PyTorch APIs for flexible data processing and inference that replace MobileModel.execute and Live Spec JSON. See the core package's README for example usage.
Closing this issue due to inactivity. Please reopen if this is still ongoing!
from playtorch.
Related Issues (20)
- PlayTorchJSIModule not found - ios & android m2 macbook pro HOT 2
- It is not possible to convert audio float32 tensor to playable uint8 audio expected by .audioFromBytes() HOT 1
- How to specify interpolation in transforms.resize?
- AudioUtil is not working on Android
- How to convert my yolov5s.pt to yolov5s.ptl HOT 1
- resize function gives error: 'Factory function resize expects 1 argument but 4 are given.'
- Cannot scan QR code from the PlayTorch app HOT 2
- playtorchjsimodule not found
- Mac M1 tutorial failure HOT 2
- unable to load local .ptl model HOT 2
- How to export a Huggingface transfromer model? HOT 3
- react_native_pytorch_core error during gradle build HOT 15
- image data fetch
- Is there a processing step im missing when using a custom trained yolo model?
- Is this project still maintained?
- Unable to work
- CMake Error
- Android build fails | Expo app using prebuild HOT 4
- 'react_native_pytorch_core-Swift.h' file not found during ios build HOT 1
- Add how to use EAS (Expo Application Service) build within this tutorial
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playtorch.