Skip to content

[Bug][Android] Build failure after 2021.3.41f1 (AGP updated from 4.2.2 to 7.4.2) #699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
manugildev opened this issue Jul 25, 2024 · 8 comments
Assignees

Comments

@manugildev
Copy link

manugildev commented Jul 25, 2024

[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:

  • Unity editor version: 2021.3.41f1
  • External Dependency Manager version: 1.2.178
  • Source you installed EDM4U: .unitypackage
  • Features in External Dependency Manager in use: Android Resolver
  • Plugins SDK in use: Firebase 12.1.0
  • Platform you are using the Unity editor on: Mac

[REQUIRED] Please describe the issue here:

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.

FAILURE: Build completed with 3 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':launcher:checkReleaseDuplicateClasses'.
> Could not resolve all files for configuration ':launcher:releaseRuntimeClasspath'.
   > Could not find com.google.firebase:firebase-analytics-unity:12.1.0.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-analytics-unity/12.1.0/firebase-analytics-unity-12.1.0.pom
       - https://repo.maven.apache.org/maven2/com/google/firebase/firebase-analytics-unity/12.1.0/firebase-analytics-unity-12.1.0.pom
       - file:/Users/manuel.gil/Downloads/Unity/firebase/New Unity Project/Library/Bee/Android/Prj/Mono2x/Gradle/unityLibrary/libs/firebase-analytics-unity-12.1.0.jar
       - file:/Users/manuel.gil/Downloads/Unity/firebase/New Unity Project/Library/Bee/Android/Prj/Mono2x/Gradle/unityLibrary/libs/firebase-analytics-unity.jar
     Required by:
         project :launcher > project :unityLibrary
   > Could not find com.google.firebase:firebase-app-unity:12.1.0.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-app-unity/12.1.0/firebase-app-unity-12.1.0.pom
       - https://repo.maven.apache.org/maven2/com/google/firebase/firebase-app-unity/12.1.0/firebase-app-unity-12.1.0.pom
       - file:/Users/manuel.gil/Downloads/Unity/firebase/New Unity Project/Library/Bee/Android/Prj/Mono2x/Gradle/unityLibrary/libs/firebase-app-unity-12.1.0.jar
       - file:/Users/manuel.gil/Downloads/Unity/firebase/New Unity Project/Library/Bee/Android/Prj/Mono2x/Gradle/unityLibrary/libs/firebase-app-unity.jar
     Required by:
         project :launcher > project :unityLibrary
     ...

Unity updated Gradle from 6.7.1 to 7.5.1 and AGP from 4.2.2 to 7.1.2 in 2021.3.41f1. This is the root cause of the issue. For Gradle 7+ the plugin repositories need to be added to settingsTemplate.gradle, not to mainTemplate.gradle.

This condition in GradleTemplateResolver.cs needs to be updated to also include versions >= than 2021.3.41f1.

return Google.VersionHandler.GetUnityVersionMajorMinor() >= 2022.2f;

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

@manugildev manugildev changed the title [Bug] Build failure after 2021.3.41f1 (which updates from Gradle 4.2.2 to Gradle 7.4.2) [Bug] Build failure after 2021.3.41f1 (AGP updated from 4.2.2 to 7.4.2) Jul 25, 2024
@argzdev argzdev removed the new to be triaged label Jul 25, 2024
@manugildev
Copy link
Author

manugildev commented Jul 26, 2024

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"
        }
    }
}

@argzdev argzdev self-assigned this Jul 29, 2024
@manugildev
Copy link
Author

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.

@argzdev
Copy link
Collaborator

argzdev commented Jul 30, 2024

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.

@manugildev
Copy link
Author

manugildev commented Jul 30, 2024

@argzdev Thanks!

As mentioned before, the most complete solution would be to modify the UnityChangeMavenRepoInSettingsTemplate method in GradleTemplateResolver.cs:

/// </summary>
public static bool UnityChangeMavenRepoInSettingsTemplate {
get {
return Google.VersionHandler.GetUnityVersionMajorMinor() >= 2022.2f;
}
}

and instead use AndroidGradlePluginVersion when AGP version is >= 7.0.0:

public static string AndroidGradlePluginVersion {
set {
androidGradlePluginVersion = value;
mainTemplateLastWriteTime = DateTime.Now;
}

Another less elegant and more bug-prone solution would be something like:

(GetUnityVersionMajorMinor() >= 2021.3.41f1 && GetUnityVersionMajorMinor() < 2022.0) || GetUnityVersionMajorMinor() >= 2022.2f;

@manugildev manugildev changed the title [Bug] Build failure after 2021.3.41f1 (AGP updated from 4.2.2 to 7.4.2) [Bug][Android] Build failure after 2021.3.41f1 (AGP updated from 4.2.2 to 7.4.2) Jul 30, 2024
@argzdev
Copy link
Collaborator

argzdev commented Jul 31, 2024

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.

@vladyslav-androshchuk
Copy link

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!

@a-maurice
Copy link
Collaborator

a-maurice commented Aug 2, 2024

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:

  1. 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.
image
  1. When this issue came up before, a user put together a script that should fix it. [Bug] Unity 2021.2 gradle fails to resolve local maven path #478 (comment) 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.

@manugildev
Copy link
Author

manugildev commented Aug 7, 2024

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants