Closed manugildev closed 1 month ago
Unity 2021.3.41f1
doesn't have the ability to add a custom settingsTemplate.gradle
from the Player > Publishing
UI, however adding a custom settingsTemplate.gradle
to Assets/Plugins/Android
will be correctly picked up and used during build.
Unity 2021.3.42f1
will come with the ability of creating a Custom Settings Template from the UI, same as in 2022.3
and Unity-6
.
Default settingsTemplate.gradle
lives in:
<EDITOR_LOCATION>/PlaybackEngines/AndroidPlayer/Tools/GradleTemplates/settingsTemplate.gradle
example:
/Applications/Unity/Hub/Editor/2021.3.41f1/PlaybackEngines/AndroidPlayer/Tools/GradleTemplates/settingsTemplate.gradle
For reference, this is the default contents of 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"
}
}
}
Also, users are experiencing this error:
ERROR:D8: com.android.tools.r8.kotlin.H
It seems to be caused by an old Kotlin version being used by some plugins, such as Firebase or Google Ads. Although setting the minSdkVersion
from 22
to 24
solves the issue, this solution is not desirable for most users.
Thanks for reporting, @manugildev. I was able to reproduce the issue. Let me reach out to our engineers and see what we can do here.
@argzdev Thanks!
As mentioned before, the most complete solution would be to modify the UnityChangeMavenRepoInSettingsTemplate
method in GradleTemplateResolver.cs
:
https://github.com/googlesamples/unity-jar-resolver/blob/8e4659acea42f83d33d34e31e48e4fdbcaa91ea0/source/AndroidResolver/src/GradleTemplateResolver.cs#L163-L168
and instead use AndroidGradlePluginVersion
when AGP version is >= 7.0.0:
Another less elegant and more bug-prone solution would be something like:
(GetUnityVersionMajorMinor() >= 2021.3.41f1 && GetUnityVersionMajorMinor() < 2022.0) || GetUnityVersionMajorMinor() >= 2022.2f;
Thank you for this suggestion, we really appreciate every contribution! I'll create a pull request with your changes, and get some feedback from our engineers.
Hello!
We have the same problem in preparing for Google own requirements. I suppose we are waiting this to be resolved on the next week?
I really appreciate your time. We have 10+ projects and loaded development pipeline, with less than 1 month till deadline we have less and less time to finish.
If we can help in any way - let me know!
Thanks for raising this issue, and helping track down a sensible solution for it. I just pushed out a new release that checks against the AGP version instead of Unity version, https://github.com/googlesamples/unity-jar-resolver/releases/tag/v1.2.182
As for the issue with ** DIR_UNITYPROJECT**
not being replaced correctly in 2021.3.41f1, unfortunately I couldn't come up with a quick enough solution that didn't indirectly cause different issues without delaying this fix till next week. However, a couple of workarounds do exist:
In your Unity project, in the Android Resolver settings (Assets > External Dependency Manager > Android Resolver > Settings), there is an option "Use Full Custom Local Maven Repo Path", "When building Android app through Unity". Checking that on will make it just use the current path of the Unity project, instead of relying on DIR_UNITYPROJECT. There are potentially some issues with that, depending on your build infrastructure, but that is the most straightforward workaround.
When this issue came up before, a user put together a script that should fix it. https://github.com/googlesamples/unity-jar-resolver/issues/478#issuecomment-980615877 I would've liked to include a script like this with the release, but because of how EDM4U ships (prebuilt binaries) adding a direct dependency on UnityEditor.Android can cause issues. But it is easy enough to copy that logic into a new file in your project, and it should be good to go.
Hopefully this will be fixed with the next 2021 release, and again, thanks for the assistance in identifying this issue.
@a-maurice
As for the issue with
** DIR_UNITYPROJECT**
not being replaced correctly in 2021.3.41f1, unfortunately I couldn't come up with a quick enough solution that didn't indirectly cause different issues without delaying this fix till next week. However, a couple of workarounds do exist
Unity 2021.3.42f1
(unityhub://2021.3.42f1) has now been released. This version solves the ** DIR_UNITYPROJECT**
not being replaced issue.
[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:
2021.3.41f1
1.2.178
.unitypackage
Android Resolver
Firebase 12.1.0
Mac
[REQUIRED] Please describe the issue here:
Assets > External Dependency Manager > Android Resolver > Resolve
Please answer the following, if applicable:
What's the issue repro rate? 100%
What happened? How can we make the problem occur?
.apk
doesn't build because of gradle failures.Unity updated Gradle from
6.7.1
to7.5.1
and AGP from4.2.2
to7.1.2
in2021.3.41f1
. This is the root cause of the issue. For Gradle 7+ the plugin repositories need to be added tosettingsTemplate.gradle
, not tomainTemplate.gradle
.This condition in GradleTemplateResolver.cs needs to be updated to also include versions >= than 2021.3.41f1.
https://github.com/googlesamples/unity-jar-resolver/blob/8e4659acea42f83d33d34e31e48e4fdbcaa91ea0/source/AndroidResolver/src/GradleTemplateResolver.cs#L166
An even better way of handling it would be to base that condition in the AGP version, instead of Unity version, and make it return true when
AGP >= 7.0.0
.More Info
→ See initial report on the Unity forums. → Reprodution project: failing_edm4u_2021_3_41f1.zip