Issue 1:
🐛 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:

Create a new React Native project using the CLI: npx react-native init AwesomeProject

Add the PyTorch android dependencies:

implementation 'org.pytorch:pytorch_android:1.4.0'
implementation 'org.pytorch:pytorch_android_torchvision:1.4.0'

Change the minSdkVersion to 21 in the root android/build.gradle

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.

Issue 2:
This failure occurs when compilation OOMs, but the OOM exit code is not propagated. "Resume build" will not fix errors like this, as resume build will reuse the (corrupted) build product.

I got this durably on a PR of mine (#14247 commit a643548); this test doesn't seem to fail on master all the time, but I did find the failure on one other PR: https://ci.pytorch.org/jenkins/job/pytorch-builds/job/py2-clang7-rocmdeb-ubuntu16.04-test/3885/console for #14482 (most other failures are the known SIGIOT problem)

Full error:

19:08:19 test_ByteTensor_mode (__main__.TestCuda) ... /usr/bin/python: symbol lookup error: /var/lib/jenkins/.local/lib/python2.7/site-packages/torch/lib/libcaffe2_hip.so: undefined symbol: THCudaByteTensor_mode
19:08:19 Traceback (most recent call last):
19:08:19 File "test/run_test.py", line 431, in <module>
19:08:19 main()
19:08:19 File "test/run_test.py", line 423, in main
19:08:19 raise RuntimeError(message)
19:08:19 RuntimeError: test_cuda failed!

log: https://ci.pytorch.org/jenkins/job/pytorch-builds/job/py2-clang7-rocmdeb-ubuntu16.04-test/3874/console