Can't integrate pytorch-mobile with react-native android app

1
open
Vergil0327
Vergil0327
Posted 1 month ago

Can't integrate pytorch-mobile with react-native android app #32408

Please provide all the information requested. Issues that do not follow this format are likely to stall.

Description

I want to integrate pytorch mobile in react-native app. though I can build successfully but get error after I invoke method

error messages: couldn't find DSO to load: libpytorch_jni.so SoSource 0: com.facebook.soloader.ApkSoSource[root=/data/data/com.example.pytorchmobile/lib-main flags = 1] ...

React Native version:

System: OS: macOS 11.4 CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @2.70GHz Memory: 96.56 MB / 8.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 12.22.6 - ~/.nvm/versions/node/v12.22.6/bin/node Yarn: 1.22.15 - /usr/local/bin/yarn npm: 6.14.15 - ~/.nvm/versions/node/v12.22.6/bin/npm Watchman: 2021.10.11.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /Users/vergil/.rvm/rubies/ruby-2.6.6/bin/pod SDKs: iOS SDK: Platforms: iOS 15.0, DriverKit 20.4, macOS 11.3, tvOS 15.0, watchOS 8.0 Android SDK: API Levels: 23, 25, 26, 27, 28, 29, 30 Build Tools: 27.0.3, 28.0.3, 29.0.2, 30.0.2 System Images: android-26 | Google APIs Intel x86 Atom_64, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom Android NDK: Not Found IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7784292 Xcode: 13.0/13A233 - /usr/bin/xcodebuild Languages: Java: 14.0.1 - /usr/bin/javac Python: 3.7.4 - /Users/vergil/opt/anaconda3/bin/python npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.66.0 => 0.66.0 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. use reate-react-native-library to create project
$ npx reate-react-native-library testproject
  1. follow instruction to add Gradle dependancies
  2. try this demo app example
  3. build android app & run

Expected Results

should load model and run successfully

Snack, code example, screenshot, or link to a repository:

I also add these to testproject > example > android > app > build.gradle to fix "More than one file was found with OS independent path 'lib/x86/libfbjni.so'" issue and prevent pytorch model from compression in the APK

...

android {
     packagingOptions {
        pickFirst 'lib/arm64-v8a/libfbjni.so'
        pickFirst 'lib/armeabi-v7a/libfbjni.so'
        pickFirst 'lib/x86/libfbjni.so'
        pickFirst 'lib/x86_64/libfbjni.so'

        pickFirst 'lib/arm64-v8a/libc++_shared.so'
        pickFirst 'lib/armeabi-v7a/libc++_shared.so'
        pickFirst 'lib/x86/libc++_shared.so'
        pickFirst 'lib/x86_64/libc++_shared.so'
    }

    aaptOptions {
        // pytorch model
        noCompress 'pt'
        noCompress 'ptl'
    }
}
cortinico
cortinico
Created 1 month ago

Seems like you also opened this other issue on PyTorch https://github.com/pytorch/pytorch/issues/66685

Have you applied the workaround suggested here: https://discuss.pytorch.org/t/pytorch-not-compatible-with-react-native-library/73841/10 Is it working for you?