yasirkula / UnityIonicIntegration

A guide to integrating Unity 3D content into an Ionic app and sending messages between them (for Android & iOS)(tested with Vuforia plugin)
104 stars 32 forks source link

Ionic 4 Duplicate Classes [ Capacitor ] #65

Closed Dev-Root2IoT closed 4 years ago

Dev-Root2IoT commented 4 years ago

Hello,

I am using UnityIonicIntegration plugin with Ionic Capacitor. Now after doing all the necessary tasks mentioned at 'yasirkula/UnityIonicIntegration', Facing below error:

Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: bitter.jnibridge.JNIBridge$a
    at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:131)
    at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:118)
    at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:102)
    at com.android.build.gradle.internal.tasks.DexMergingTaskRunnable.run(DexMergingTask.kt:444)
    ... 28 more
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
    at com.android.tools.r8.utils.t.a(:55)
    at com.android.tools.r8.D8.run(:11)
    at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:116)
    ... 30 more
Caused by: com.android.tools.r8.utils.AbortException: Error: Program type already present: bitter.jnibridge.JNIBridge$a

This is because of multiple 'unity-classes.jar', 1 is present at 'capacitor-cordova-android-plugins\src\main\libs' and 2 at UnityAndroidApp\libs

Removing either one causes class not found error.

Please help me resolve this issue.

Thanks

SOLVED

Inside android studio Module Settings, Created a new module [Import .JAR/.ARR Package] added path of unity-classes.jar (Created a externalLib folder in project root and placed jar here). Now in dependencies tab, Removed unity-classes.jar from both present at 'capacitor-cordova-android-plugins\src\main\libs' and UnityAndroidApp\libs. Now declared new jar module as dependency in both the module fixed this issue.

yasirkula commented 4 years ago

Great fix, thanks for sharing!