<p dir="auto"><g-emoji class="g-emoji" alias="bug" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f41b.png">🐛</g-emoji> Bug</p>
<p dir="auto">PyTorch Java Native Interface is conflicting with React Native one. (they both use fbjni with a slightly different version).<br>
This cause issue during the android build in an React Native project:</p>
<p dir="auto">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)<br>
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)<br>
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)<br>
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)<br>
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)<br>
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)<br>
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)<br>
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)<br>
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)<br>
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)<br>
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)<br>
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)<br>
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)<br>
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)<br>
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)<br>
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)</p>
<p dir="auto">To Reproduce</p>
<p dir="auto">Steps to reproduce the behavior:</p>
<p dir="auto">Create a new React Native project using the CLI: npx react-native init AwesomeProject<br>
Add the PyTorch android dependencies:<br>
implementation 'org.pytorch:pytorch_android:1.4.0'<br>
implementation 'org.pytorch:pytorch_android_torchvision:1.4.0'<br>
Change the minSdkVersion to 21 in the root android/build.gradle<br>
Sync gradle and build the android app<br>
Expected behavior</p>
<p dir="auto">The Application should be able to build without having "duplicate class" issue and start on the device</p>
<p dir="auto">Environment</p>
<p dir="auto">➜ python collect_env.py<br>
Collecting environment information...<br>
PyTorch version: N/A - 1.4.0<br>
Is debug build: N/A<br>
CUDA used to build PyTorch: N/A</p>
<p dir="auto">OS: Mac OSX 10.15.5 (x86_64)<br>
GCC version: Could not collect<br>
Clang version: 11.0.3 (clang-1103.0.32.62)<br>
CMake version: Could not collect</p>
<p dir="auto">Python version: 2.7 (64-bit runtime)<br>
Is CUDA available: N/A<br>
CUDA runtime version: Could not collect<br>
GPU models and configuration: Could not collect<br>
Nvidia driver version: Could not collect<br>
cuDNN version: Could not collect</p>
<p dir="auto">Versions of relevant libraries:<br>
[pip] numpy==1.8.0rc1<br>
[conda] Could not collect<br>
Additional context</p>
<p dir="auto">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.</p>
<h2 dir="auto"><g-emoji class="g-emoji" alias="books" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f4da.png">📚</g-emoji> Documentation</h2>

<hr>
<p dir="auto">I am a fan of pytorch in China.<br>
The purpose of our visit is very simple, apply for translation of the Chinese version, I hope to get the relevant authorization!<br>
(Sorry: the official website did not find your email)</p>
<p dir="auto">There are several reasons:</p>
<ol dir="auto">
<li>The English level of many Chinese users is not very good.</li>
<li>Network problems, you know (China's magic network)!</li>
<li>Online blogs are very messy.</li>
</ol>
<p dir="auto">We are <a href="http://www.apachecn.org" rel="nofollow">ApacheCN</a>, China's open source small organization, and hope to do some translation to help more people learn, our website:  <a href="http://www.apachecn.org" rel="nofollow">http://www.apachecn.org</a></p>
<p dir="auto">We have previously translated pytorch:  <a href="https://pytorch.apachecn.org" rel="nofollow">https://pytorch.apachecn.org</a><br>
If you like, we will continue to help translate the Chinese version of pytorch.</p>