googlesamples / unity-jar-resolver

Unity plugin which resolves Android & iOS dependencies and performs version management
Other
1.21k stars 337 forks source link

[Bug] Resolving Android dependencies not working. #618

Closed SpertsyanKM closed 1 year ago

SpertsyanKM commented 1 year ago

[READ] For Firebase Unity SDK issues, please report to Firebase Unity Sample

Once you've read this section and determined that your issue is appropriate for this repository, please delete this section.

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

I've run into the same issue I've reported half a year ago. I'm creating a new Unity project from scratch. I import unity-jar-resolver and add a library I've already used before in other projects. Then I force run Android resolver and it gets hung up trying to resolve the dependencies, but all of the almost 30 attempts fail with the conflicts similar to the described below:

Resolution attempt 1: packages [com.fasterxml.jackson.core:jackson-databind:2.11.1, my.dependency.one:sdk:1.0.0, org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.61]
androidx.activity:activity conflicting due to package(s):
- my.dependency.one:sdk:1.0.0/androidx.preference:preference:1.2.0/androidx.appcompat:appcompat:1.1.0/androidx.activity:activity:1.5.1
- my.dependency.one:sdk:1.0.0/androidx.preference:preference:1.2.0/androidx.appcompat:appcompat:1.1.0/androidx.fragment:fragment:1.3.6/androidx.activity:activity:1.2.4
- my.dependency.one:sdk:1.0.0/androidx.preference:preference:1.2.0/androidx.fragment:fragment-ktx:1.3.6/androidx.activity:activity-ktx:1.2.2/androidx.activity:activity:[1.2.2]
- my.dependency.one:sdk:1.0.0/androidx.preference:preference:1.2.0/androidx.fragment:fragment-ktx:1.3.6/androidx.fragment:fragment:[1.3.6]/androidx.activity:activity:1.2.4
- my.dependency.one:sdk:1.0.0/my.dependency.two:sdk:4.0.0/androidx.appcompat:appcompat:1.5.1/androidx.activity:activity:1.5.1
- my.dependency.one:sdk:1.0.0/my.dependency.two:sdk:4.0.0/androidx.appcompat:appcompat:1.5.1/androidx.fragment:fragment:1.3.6/androidx.activity:activity:1.2.4
- my.dependency.one:sdk:1.0.0/my.dependency.two:sdk:4.0.0/androidx.constraintlayout:constraintlayout:2.1.4/androidx.appcompat:appcompat:1.2.0/androidx.activity:activity:1.5.1
androidx.fragment:fragment conflicting due to package(s):
- my.dependency.one:sdk:1.0.0/androidx.preference:preference:1.2.0/androidx.appcompat:appcompat:1.1.0/androidx.fragment:fragment:1.3.6
- my.dependency.one:sdk:1.0.0/androidx.preference:preference:1.2.0/androidx.fragment:fragment-ktx:1.3.6/androidx.fragment:fragment:[1.3.6]
- my.dependency.one:sdk:1.0.0/my.dependency.two:sdk:4.0.0/androidx.appcompat:appcompat:1.5.1/androidx.fragment:fragment:1.3.6
- my.dependency.one:sdk:1.0.0/my.dependency.two:sdk:4.0.0/androidx.constraintlayout:constraintlayout:2.1.4/androidx.appcompat:appcompat:1.2.0/androidx.fragment:fragment:1.3.6
- my.dependency.one:sdk:1.0.0/my.dependency.two:sdk:4.0.0/androidx.preference:preference:1.2.0/androidx.appcompat:appcompat:1.1.0/androidx.fragment:fragment:1.3.6
- my.dependency.one:sdk:1.0.0/my.dependency.two:sdk:4.0.0/androidx.preference:preference:1.2.0/androidx.fragment:fragment-ktx:1.3.6/androidx.fragment:fragment:[1.3.6]
androidx.fragment:fragment-ktx conflicting due to package(s):
- my.dependency.one:sdk:1.0.0/androidx.preference:preference:1.2.0/androidx.fragment:fragment-ktx:1.3.6
- my.dependency.one:sdk:1.0.0/my.dependency.two:sdk:4.0.0/androidx.preference:preference:1.2.0/androidx.fragment:fragment-ktx:1.3.6

If I try to use Custom Main Gradle Template and Custom Gradle Properties Template resolution finishes successfully and instantly, but then exported Android project fails to compile with the following errors:

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':launcher:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class android.support.v4.app.RemoteActionCompatParcelizer found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and jetified-androidx.core.core-1.12.0-alpha03-runtime (:androidx.core.core-1.12.0-alpha03:)
     Duplicate class android.support.v4.graphics.drawable.IconCompatParcelizer found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and jetified-androidx.core.core-1.12.0-alpha03-runtime (:androidx.core.core-1.12.0-alpha03:)
     Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and jetified-androidx.core.core-1.12.0-alpha03-runtime (:androidx.core.core-1.12.0-alpha03:)
     Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and jetified-androidx.core.core-1.12.0-alpha03-runtime (:androidx.core.core-1.12.0-alpha03:)
     Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and jetified-androidx.core.core-1.12.0-alpha03-runtime (:androidx.core.core-1.12.0-alpha03:)
     Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and jetified-androidx.core.core-1.12.0-alpha03-runtime (:androidx.core.core-1.12.0-alpha03:)
     Duplicate class androidx.appcompat.app.ActionBar found in modules appcompat-1.2.0-runtime (androidx.appcompat:appcompat:1.2.0) and jetified-androidx.appcompat.appcompat-1.7.0-alpha02-runtime (:androidx.appcompat.appcompat-1.7.0-alpha02:)
     Duplicate class androidx.appcompat.app.ActionBar$DisplayOptions found in modules appcompat-1.2.0-runtime (androidx.appcompat:appcompat:1.2.0) and jetified-androidx.appcompat.appcompat-1.7.0-alpha02-runtime (:androidx.appcompat.appcompat-1.7.0-alpha02:)
     Duplicate class androidx.appcompat.app.ActionBar$LayoutParams found in modules appcompat-1.2.0-runtime (androidx.appcompat:appcompat:1.2.0) and jetified-androidx.appcompat.appcompat-1.7.0-alpha02-runtime (:androidx.appcompat.appcompat-1.7.0-alpha02:)
     Duplicate class androidx.appcompat.app.ActionBar$NavigationMode found in modules appcompat-1.2.0-runtime (androidx.appcompat:appcompat:1.2.0) and jetified-androidx.appcompat.appcompat-1.7.0-alpha02-runtime (:androidx.appcompat.appcompat-1.7.0-alpha02:)
     Duplicate class androidx.appcompat.app.ActionBar$OnMenuVisibilityListener found in modules appcompat-1.2.0-runtime (androidx.appcompat:appcompat:1.2.0) and jetified-androidx.appcompat.appcompat-1.7.0-alpha02-runtime (:androidx.appcompat.appcompat-1.7.0-alpha02:)
... (3 k more lines like these)
Duplicate class androidx.viewpager.widget.ViewPager$SavedState$1 found in modules jetified-androidx.viewpager.viewpager-1.0.0-runtime (:androidx.viewpager.viewpager-1.0.0:) and viewpager-1.0.0-runtime (androidx.viewpager:viewpager:1.0.0)
Duplicate class androidx.viewpager.widget.ViewPager$SimpleOnPageChangeListener found in modules jetified-androidx.viewpager.viewpager-1.0.0-runtime (:androidx.viewpager.viewpager-1.0.0:) and viewpager-1.0.0-runtime (androidx.viewpager:viewpager:1.0.0)
Duplicate class androidx.viewpager.widget.ViewPager$ViewPositionComparator found in modules jetified-androidx.viewpager.viewpager-1.0.0-runtime (:androidx.viewpager.viewpager-1.0.0:) and viewpager-1.0.0-runtime (androidx.viewpager:viewpager:1.0.0)

Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
    at com.android.build.gradle.internal.tasks.CheckDuplicateClassesDelegate.run(CheckDuplicateClassesDelegate.kt:71)
    at com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable.execute(CheckDuplicateClassesDelegate.kt:98)
    at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:66)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:62)
    at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:97)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1.lambda$execute$0(NoIsolationWorkerFactory.java:62)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:62)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.lambda$call$2(DefaultBuildOperationExecutor.java:79)
    at org.gradle.internal.operations.UnmanagedBuildOperationWrapper.callWithUnmanagedSupport(UnmanagedBuildOperationWrapper.java:54)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:79)
    at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:59)
    at org.gradle.workers.internal.DefaultWorkerExecutor.lambda$submitWork$2(DefaultWorkerExecutor.java:206)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:214)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131)
    ... 3 more

==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':launcher:mergeDebugJavaResource'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
   > 2 files found with path 'META-INF/androidx.preference_preference.version' from inputs:
      - /Users/kamospertsyan/.gradle/caches/transforms-3/d782c7801642a9dacc81a53da55669b0/transformed/jetified-androidx.preference.preference-1.2.0/jars/classes.jar
      - /Users/kamospertsyan/.gradle/caches/transforms-3/57ae54d1450b10a5b6d4c77777310814/transformed/preference-1.1.1/jars/classes.jar
     Adding a packagingOptions block may help, please refer to
     https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html
     for more information

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':launcher:mergeDebugJavaResource'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:188)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:186)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:174)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:109)
    at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
    ... (a long-long stacktrace)

==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

Jetifier is enabled both in unity-jar-resolver and in gradle properties.

Please answer the following, if applicable:

What's the issue repro rate? 100%

What happened? How can we make the problem occur?

If you have a downloadable sample project that reproduces the bug you're reporting, you will likely receive a faster response on your issue.

Here is a repo with that empty project. In build settings switch to Android and set the following checks - Export project, Development build, Script debugging. By the way it's just a new project where I've just added unity-jar-resolver and the following dependency: "com.qonversion.unity": "https://github.com/qonversion/unity-sdk.git#4.3.0"

paulinon commented 1 year ago

Hi @SpertsyanKM,

Thanks for bringing this up. I haven't come across the error message you're facing with your Android project so far. Have you tried if going to Assets > Play Services Resolver > Android Resolver > Delete Resolved Libraries makes any difference with your implementation? Additionally, does building directly from Unity instead of exporting to an Android project return any error messages?

SpertsyanKM commented 1 year ago

Hi, @paulinon. Thanks for advices, but they didn't help.

If I build directly from Unity, it fails with the same errors, as the exported project built from Android Studio. If I delete resolved libraries before, it fails with a lot of cannot find symbol errors for missing dependencies.

paulinon commented 1 year ago

Hi @SpertsyanKM,

I noticed that you imported the resolver via the .unitypackage file while the dependency you indicated is via the Unity Package Manager. Could you try if importing the resolver via the Package Manager makes a difference in your implementation? You can find the .tgz file here.

SpertsyanKM commented 1 year ago

Well, I've created a new Unity project, added there the Unity Jar Resolver package via the Package Manager, and tried different variants:

SpertsyanKM commented 1 year ago

Any help would be appreciated as the problem persists

paulinon commented 1 year ago

Hi @SpertsyanKM,

I'm still unsuccessful in reproducing the error message you encountered using the sample project you provided. Is it possible to replicate this issue from an empty Unity project? Additionally, does the issue persist after updating your dependency to its latest version?

SpertsyanKM commented 1 year ago

Yes, the issue is reproducible from an empty unity project, as I wrote here. I use the latest version of Qonversion SDK, which also was successfully built earlier.

SpertsyanKM commented 1 year ago

I've tried to resolve dependencies for several last versions of Qonversion SDK and found that resolving begins failing from version 4.1.0.

The only difference in dependencies of that version in comparison with the previous one is that in 4.1.0 there appeared a new dependency (transited from a nested dependency):

How can I help UJR to resolve my dependencies? To be honest, I don't even understand, what has changed from my last successful resolving attempts, but all those Qonversion SDK versions were successfully resolving till this month.

Note - I'm trying to resolve dependencies the way I was able to do it before - without any custom gradle template and other files (all the checkboxes are unselected).

SpertsyanKM commented 1 year ago

I started everything again from scratch and was finally able to build the app. What was different from my previous failed attempt is that I started building the new project with custom gradle templates straightaway. And that helped me to resolve the dependencies and successfully build and run the app both from Unity and Android Studio.

I think my previous problem with duplicate files was caused by the jars, added while resolving without custom gradle files enabled. The strange thing is that even the "Delete Resolved Libraries" option didn't help.

The only problem that is left is the failure to resolve dependencies without custom gradle files (without any reasons for that failure), but as the workaround finally worked, I think, we can close this issue.

P.S. Also linking a similar issue I've found while searching for a solution - #444.