[빌드에러] Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'unityLibrary\build.gradle'
[추가] 2023-07-20
Unity 2022.3.5f1에서 이슈 해결된 것 확인함
(몇 버전부터 해결된건지는 확인 못함)
--------------------------------------------------
Unity 2022.2.18f1
Firebase 10.7.0
----
[빌드에러 #1]
> Configure project :unityLibrary
Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'unityLibrary\build.gradle'
...
[빌드에러 #2]
Execution failed for task ':launcher:checkReleaseDuplicateClasses'.
> Could not resolve all files for configuration ':launcher:releaseRuntimeClasspath'.
-------------------------------------------------------------------------------------------------------------
Unity 2021에서 Unity 2022로 포팅하는 중에 위와 같은 빌드 에러가 떠서 찾아보니
Gradle 관련 Unity 2022 버그가 있는 것 같다.
[수정]
[참조] 링크 내용대로 아래와 같이 Gradle을 수정하고 정상적으로 빌드 되는 걸 확인 함.
간단히 정리하면 settingsTemplate.gradle에 있던 걸 baseProjectTemplate.gradle로 옮겨야 한다.
-------------------------------------------------------------------------------------------------------------
256p commented on Jan 24
Also, there is another workaround that keeps the Gradle version (in case some android lib requires it).
For that workaround, you will need to copy a file from /Applications/Unity/Hub/Editor/2022.2.3f1/PlaybackEngines/AndroidPlayer/Tools/GradleTemplates/settingsTemplate.gradle to Assets/Plugins/Android/settingsTemplate.gradle. That way Unity will use your template in Assets/Plugins/Android. (It's weird that Unity doesn't has a checkbox for that)
For my version of unity, it looks like that:
[Before] ../Assets/Plugins/Android/settingsTemplate.gradle
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"
}
}
}
The conflicting part is RepositoriesMode.PREFER_SETTINGS. But you can safely delete the whole dependencyResolutionManagement block from here. Since the android project still needs to know about local dependencies, copy the repositories block, you will need it later.
Now settingsTemplate.gradle should look like this:
[After] ../Assets/Plugins/Android/settingsTemplate.gradle
pluginManagement {
repositories {
**ARTIFACTORYREPOSITORY**
gradlePluginPortal()
google()
mavenCentral()
}
}
include ':launcher', ':unityLibrary'
**INCLUDES**
------------------------------------------------------------------------------------------------------------------------------------------
Now in Project Settings > Player > Publishing Settings for Android enable Custom Base Gradle Template
Initially, it will look like that:
[Before] ../Assets/Plugins/Android/baseProjectTemplate.gradle
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
**BUILD_SCRIPT_DEPS**
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Now create allprojects block and paste repositories copied in the settings template. As a result base template will look like that:
[After] ../Assets/Plugins/Android/baseProjectTemplate.gradle
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
}
Now Gradle should build successfully.
-------------------------------------------------------------------------------------------------------------
[참조] https://github.com/googlesamples/unity-jar-resolver/issues/594
'Unity3D > Trouble Shooting' 카테고리의 다른 글
[Crash/Android] signal 6 (SIGABRT), code -1 (SI_QUEUE) (0) | 2024.02.13 |
---|---|
[Editor] CommandInvokationFailure: Failed to update Android SDK package list. (0) | 2024.02.13 |
[링크] [Unity] 게임 재실행시 튕기는 오류 (0) | 2023.05.04 |
[Tip] Unity - Memory Profiler에서 보이는 System.Byte[] (0) | 2023.04.07 |
[XCode] [!] Cocoapods could not find compatible versions for pod "GTMSessionFetcher/Core" (0) | 2023.03.27 |