I'm making a mobile game using Unity for Android. My problem is, every time I try to build the project I get this error :
CommandInvokationFailure: Gradle build failed. C:\Program Files\Unity\Hub\Editor\2022.1.17f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2022.1.17f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-6.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease" stderr[ FAILURE: Build failed with an exception.
- What went wrong: Could not determine the dependencies of task ':launcher:lintVitalRelease'.
This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry. The following AndroidX dependencies are detected: androidx.fragment:fragment:1.0.0, androidx.slidingpanelayout:slidingpanelayout:1.0.0, androidx.versionedparcelable:versionedparcelable:1.1.0, androidx.core:core:1.2.0, androidx.customview:customview:1.0.0, androidx.swiperefreshlayout:swiperefreshlayout:1.0.0, androidx.interpolator:interpolator:1.0.0, androidx.loader:loader:1.0.0, androidx.drawerlayout:drawerlayout:1.0.0, androidx.viewpager:viewpager:1.0.0, androidx.collection:collection:1.0.0, androidx.localbroadcastmanager:localbroadcastmanager:1.0.0, androidx.lifecycle:lifecycle-common:2.0.0, androidx.arch.core:core-common:2.0.0, androidx.annotation:annotation:1.2.0, androidx.startup:startup-runtime:1.0.0, androidx.tracing:tracing:1.0.0, androidx.legacy:legacy-support-core-ui:1.0.0, androidx.lifecycle:lifecycle-livedata:2.0.0, androidx.lifecycle:lifecycle-viewmodel:2.0.0, androidx.lifecycle:lifecycle-livedata-core:2.0.0, androidx.arch.core:core-runtime:2.0.0, androidx.legacy:legacy-support-core-utils:1.0.0, androidx.documentfile:documentfile:1.0.0, androidx.cursoradapter:cursoradapter:1.0.0, androidx.lifecycle:lifecycle-runtime:2.0.0, androidx.coordinatorlayout:coordinatorlayout:1.0.0, androidx.asynclayoutinflater:asynclayoutinflater:1.0.0, androidx.print:print:1.0.0
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
- BUILD FAILED in 18s Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 ] stdout[ Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
Configure project :launcher WARNING: The option setting 'android.enableR8=false' is deprecated. It will be removed in version 5.0 of the Android Gradle plugin. You will no longer be able to disable R8 Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.1.17f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\30.0.2\package.xml. Probably the SDK is read-only Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.1.17f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools\package.xml. Probably the SDK is read-only Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.1.17f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-29\package.xml. Probably the SDK is read-only Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.1.17f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-30\package.xml. Probably the SDK is read-only etc...
So then I tried adding the property "android.useAndroidX=true" in the gradleTemplate.properties file. Here is the code :
org.gradle.jvmargs=-Xmx**JVM_HEAP_SIZE**M
org.gradle.parallel=true
unityStreamingAssets=**STREAMING_ASSETS**
**ADDITIONAL_PROPERTIES**
android.useAndroidX=true
But it resulted in a new error :
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':launcher:checkReleaseDuplicateClasses'.
1 exception was raised by workers: java.lang.RuntimeException: Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.2.0-runtime.jar (androidx.core:core:1.2.0) and support-compat-26.1.0-runtime.jar (com.android.support:support-compat:26.1.0) Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.2.0-runtime.jar (androidx.core:core:1.2.0) and support-compat-26.1.0-runtime.jar (com.android.support:support-compat:26.1.0) Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.2.0-runtime.jar (androidx.core:core:1.2.0) and support-compat-26.1.0-runtime.jar (com.android.support:support-compat:26.1.0) Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.2.0-runtime.jar (androidx.core:core:1.2.0) and support-compat-26.1.0-runtime.jar (com.android.support:support-compat:26.1.0) Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.2.0-runtime.jar (androidx.core:core:1.2.0) and support-compat-26.1.0-runtime.jar (com.android.support:support-compat:26.1.0) Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.2.0-runtime.jar (androidx.core:core:1.2.0) and support-compat-26.1.0-runtime.jar (com.android.support:support-compat:26.1.0) Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.2.0-runtime.jar (androidx.core:core:1.2.0) and support-compat-26.1.0-runtime.jar (com.android.support:support-compat:26.1.0) Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.2.0-runtime.jar (androidx.core:core:1.2.0) and support-compat-26.1.0-runtime.jar (com.android.support:support-compat:26.1.0) Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.2.0-runtime.jar (androidx.core:core:1.2.0) and support-compat-26.1.0-runtime.jar (com.android.support:support-compat:26.1.0) Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.2.0-runtime.jar (androidx.core:core:1.2.0) and support-compat-26.1.0-runtime.jar (com.android.support:support-compat:26.1.0) Go to the documentation to learn how to Fix dependency resolution errors.
I think the core error might come from the unity mediation package, as the build started failing when I added it. Another clue is that whenever I try to resolve android dependencies using the mobile dependencies resolver, I get a warning log saying that there is a dependencies conflict involving this package. I created a topic about it at How to solve this dependencies conflict warning using Unity Mediation? Thanks in advance for your answers.