Git Product home page Git Product logo

Comments (9)

raedle avatar raedle commented on July 3, 2024 2

@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 fbjni 0.0.2
  • PyTorch Android 1.10.0 bundles fbjni 0.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.

  1. Upgrade the React Native version to 0.65.1 (which has fbjni 0.0.3, see React Native 0.65.0 CHANGELOG.md)
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
  1. Build the apk on linux, unpack contents, change libfbjni.so, repackage apk

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.

chrisklaiber avatar chrisklaiber commented on July 3, 2024

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.

yMayanand avatar yMayanand commented on July 3, 2024

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.

raedle avatar raedle commented on July 3, 2024

@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

The project is currently building for arm64-v8a, armeabi-v7a, x86, and x86_64.

from playtorch.

yMayanand avatar yMayanand commented on July 3, 2024

@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.

raedle avatar raedle commented on July 3, 2024

@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.

akashraj9828 avatar akashraj9828 commented on July 3, 2024

@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

image

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

image

from playtorch.

yMayanand avatar yMayanand commented on July 3, 2024

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.

raedle avatar raedle commented on July 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.