Extending the UnityPlayerActivity Java Code fail to build

Hello Guys,

I’m trying to follow the instructions mentioned in this 1 to extend the UnityPlayerActivity in Android studio and use my new custom activity from unity C#,

The problem is that when i build the project i get this error:

Execution failed for task ':transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lbitter/jnibridge/JNIBridge$a;

How to fix this error, any help is appreciated.

Answering my own question,

After struggling for two days i found the answer.

Unity adds its own classes automatically to the project when building the application. If you bundle them with your library, they will get added twice, I resolved this issue by using “exclude” and “provided” configurations in build.gradle

For a complete explanation for this problem see this link: Error building Android Library for Unity 3D 5.3 - Android Studio - Stack Overflow