Execution failed for task ':launcher:checkReleaseDuplicateClasses'
Unity: 2022
The error Execution failed for task ':launcher:checkReleaseDuplicateClasses'. > Could not resolve all dependencies for configuration ':launcher:releaseRuntimeClasspath' happens because Unity switched to the new Android Gradle Plugin version (7.1.0). In this version, the repository setting was moved from the top-level build.gradle file to the setting.gradle file.
The error example from Unity Editor Log:
Execution failed for task ':launcher:checkReleaseDuplicateClasses'. > Could not resolve all files for configuration ':launcher:releaseRuntimeClasspath'. > Could not find com.appodeal.ads.sdk.core:internal:3.0.2. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/appodeal/ads/sdk/core/internal/3.0.2/internal-3.0.2.pom - https://repo.maven.apache.org/maven2/com/appodeal/ads/sdk/core/internal/3.0.2/internal-3.0.2.pom - file:/D:/UnityProjects/natrix/natrix/Library/Bee/Android/Prj/IL2CPP/Gradle/unityLibrary/libs/internal-3.0.2.jar - file:/D:/UnityProjects/natrix/natrix/Library/Bee/Android/Prj/IL2CPP/Gradle/unityLibrary/libs/internal.jar Required by: project :launcher > project :unityLibrary
Workaround
To solve the error please complete the following steps:
At first you need to copy a settingsTemplate.gradle file from /Applications/Unity/Hub/Editor/2022.2.3f1/PlaybackEngines/AndroidPlayer/Tools/GradleTemplates/settingsTemplate.gradle
and duplicate it to Assets/Plugins/Android/settingsTemplate.gradle. So Unity can use the one from Assets/Plugins/Android.
The settingsTemplate.gradle sample :
pluginManagement { repositories { **ARTIFACTORYREPOSITORY** gradlePluginPortal() google() mavenCentral() } } include ':launcher', ':unityLibrary' **INCLUDES** dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) repositories { **ARTIFACTORYREPOSITORY** google() mavenCentral() flatDir { dirs "${project(':unityLibrary').projectDir}/libs" } } }
Copy the repositories block from dependencyResolutionManagement and safely delete dependencyResolutionManagement block from here.
Now settingsTemplate.gradle should look like this:
pluginManagement { repositories { **ARTIFACTORYREPOSITORY** gradlePluginPortal() google() mavenCentral() } } include ':launcher', ':unityLibrary' **INCLUDES**
In Project Settings > Player > Publishing Settings for Android enable Custom Base Gradle Template and create allprojects block.
Paste repositories copied in the settings template.
As a result baseProjectTemplate.gradle will look like the one below:
plugins { id 'com.android.application' version '7.1.2' apply false id 'com.android.library' version '7.1.2' apply false **BUILD_SCRIPT_DEPS** } allprojects { repositories { **ARTIFACTORYREPOSITORY** google() mavenCentral() flatDir { dirs "${project(':unityLibrary').projectDir}/libs" } } } task clean(type: Delete) { delete rootProject.buildDir }
The build should succeed now.