dclipca
dclipca

Reputation: 1937

Dependencies of an Android plugin for Unity collide with the dependencies downloaded by unity-jar-resolver

There is this situation where I am trying to use MLKit inside Unity. Naturally I make an Android plugin. Here are the Gradle dependencies:

dependencies {
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    implementation "androidx.camera:camera-camera2:1.1.0-alpha02"
    implementation "com.google.mlkit:pose-detection:17.0.1-beta3"
}

Then I compile the .aar using

task copyPlugin(type: Copy) {
    dependsOn assemble
    from ('build/outputs/aar')
    into ('../../../Assets/Plugins/Android')
    include (project.name + '-release.aar')
}

What happens next is that Unity is not able to access androidx.camera:camera-camera2:1.1.0-alpha02 or com.google.mlkit:pose-detection:17.0.1-beta3. Because of this, I have to use unity-jar-resolver to download the dependencies so that Unity will link them with the resulting app. I expected everything will work but now the dependencies seem to collide. Can you give me an insight into this? Here is the Unity build error:

* What went wrong:
Execution failed for task ':launcher:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
  java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class androidx.camera.camera2.Camera2Config found in modules PoseDetector-release-runtime.jar (:PoseDetector-release:) and androidx.camera.camera-camera2-1.1.0-alpha02-runtime.jar (:androidx.camera.camera-camera2-1.1.0-alpha02:)
  Duplicate class androidx.camera.camera2.Camera2Config$DefaultProvider found in modules PoseDetector-release-runtime.jar (:PoseDetector-release:) and androidx.camera.camera-camera2-1.1.0-alpha02-runtime.jar (:androidx.camera.camera-camera2-1.1.0-alpha02:)
  Duplicate class androidx.camera.camera2.impl.Camera2CameraCaptureResultConverter found in modules PoseDetector-release-runtime.jar (:PoseDetector-release:) and androidx.camera.camera-camera2-1.1.0-alpha02-runtime.jar (:androidx.camera.camera-camera2-1.1.0-alpha02:)

Upvotes: 1

Views: 1212

Answers (1)

Daveloper
Daveloper

Reputation: 758

As the error message suggests, the same stuff seams to be around in two separate dependencies: once in ":PoseDetector-release:" and once in ":androidx.camera.camera-camera2-1.1.0-alpha02:"

I have run in this issue before, and was able to solve it. Sometimes it takes longer to find out which dependencies to remove.

The solution to this error is to remove one of the duplicate dependencies, in my case I believe it was removing the android plugin folder of some SDK in my Project's Assets Folder, due to the fact that the same dependency was already included by some package I downloaded and imported via the unity package manager.

The two cases I can think of, where my answer is garbage are:

  • The collision is NOT due to collision between same dependencies, but just between namespaces

  • You can not remove neither of the two dependencies because they only overlap, but BOTH each contain MORE stuff you need, which is NOT already included in the other one

Upvotes: 1

Related Questions