Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android PyTorch conflict with the JNI (fbjni) of React Native #43142

Closed
HugoGresse opened this issue Aug 17, 2020 · 1 comment
Closed

Android PyTorch conflict with the JNI (fbjni) of React Native #43142

HugoGresse opened this issue Aug 17, 2020 · 1 comment

Comments

@HugoGresse
Copy link

🐛 Bug

PyTorch Java Native Interface is conflicting with React Native one. (they both use fbjni with a slightly different version).
This cause issue during the android build in an React Native project:

java.lang.RuntimeException: Duplicate class com.facebook.jni.CppException found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)
  Duplicate class com.facebook.jni.CppSystemErrorException found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)
  Duplicate class com.facebook.jni.DestructorThread found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)
  Duplicate class com.facebook.jni.DestructorThread$1 found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)
  Duplicate class com.facebook.jni.DestructorThread$Destructor found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)
  Duplicate class com.facebook.jni.DestructorThread$DestructorList found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)
  Duplicate class com.facebook.jni.DestructorThread$DestructorStack found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)
  Duplicate class com.facebook.jni.DestructorThread$Terminus found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)
  Duplicate class com.facebook.jni.HybridClassBase found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)
  Duplicate class com.facebook.jni.HybridData found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)
  Duplicate class com.facebook.jni.HybridData$Destructor found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)
  Duplicate class com.facebook.jni.IteratorHelper found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)
  Duplicate class com.facebook.jni.MapIteratorHelper found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)
  Duplicate class com.facebook.jni.NativeRunnable found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)
  Duplicate class com.facebook.jni.ThreadScopeSupport found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)
  Duplicate class com.facebook.jni.UnknownCppException found in modules fbjni-java-only-0.0.3.jar (com.facebook.fbjni:fbjni-java-only:0.0.3) and pytorch_android_fbjni-1.4.0-runtime.jar (org.pytorch:pytorch_android_fbjni:1.4.0)

To Reproduce

Steps to reproduce the behavior:

  1. Create a new React Native project using the CLI: npx react-native init AwesomeProject
  2. Add the PyTorch android dependencies:
        implementation 'org.pytorch:pytorch_android:1.4.0'
        implementation 'org.pytorch:pytorch_android_torchvision:1.4.0'
  1. Change the minSdkVersion to 21 in the root android/build.gradle
  2. Sync gradle and build the android app

Expected behavior

The Application should be able to build without having "duplicate class" issue and start on the device

Environment

➜ python collect_env.py
Collecting environment information...
PyTorch version: N/A - 1.4.0
Is debug build: N/A
CUDA used to build PyTorch: N/A

OS: Mac OSX 10.15.5 (x86_64)
GCC version: Could not collect
Clang version: 11.0.3 (clang-1103.0.32.62)
CMake version: Could not collect

Python version: 2.7 (64-bit runtime)
Is CUDA available: N/A
CUDA runtime version: Could not collect
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect

Versions of relevant libraries:
[pip] numpy==1.8.0rc1
[conda] Could not collect

Additional context

There were some talk on the PyTorch forum here saying that someone (from PyTorch team?) was discussing with the RN Team, but there is no update since March 20 AND the issue come after the reported issue here.

@HugoGresse
Copy link
Author

Using the version 1.5.0 resolved this issue, just had minor issue with duplicated fbjni.so that I've solve using

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

Though this may have some issue in production.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant