hms-unity-plugin icon indicating copy to clipboard operation
hms-unity-plugin copied to clipboard

Build for Android fails after Updating Unity version and Target API to 34

Open SMahdiFaghih opened this issue 1 year ago • 12 comments

Describe the bug & problem After updating my Target API to 34 (Android 14) and also updating Unity version to 2021.3.42f1, now i have problem building the game for Android. Before doint so, the build worked correctly on version 2.3.8 but after that it raised the following error. Also updating to 2.3.9 did not help.

After these updates the dependencies inside mainTemplate.gradle should be moved to settingsTemplate.gradle and the error occurs on hmsBaseProjectTemplate.gradle line 7 as follows:

What went wrong: A problem occurred evaluating script.

Cannot change dependencies of dependency configuration ':classpath' after it has been resolved.

Since this file is generated on build, modifing it won't help. Moving this classpath depencency to mainTemplate.gradle also did not help. The dependency does nto resolve by External Dependency Manager on Force Resolve.

At this point, i don't know what the solution might be and i need your help yo fix this problem.

Environment (please complete the following information):

  • Unity Version 2021.3.42f1
  • HMS Unity Plugin Version 2.3.8 and 2.3.9

SMahdiFaghih avatar Sep 15 '24 08:09 SMahdiFaghih

Thank you for reporting this issue/advice.

We will get back to you as soon as possible.
Would you like to star our plugin to support us? :sparkles:

github-actions[bot] avatar Sep 15 '24 08:09 github-actions[bot]

I also affected this problem

PromanSEW avatar Oct 04 '24 04:10 PromanSEW

Hi @SMahdiFaghih @PromanSEW

After upgrading the Target API to 34 (Android 14) and updating Unity to version 2021.3.42f1, you encountered an issue during the build process. The error appears on line 7 of hmsBaseProjectTemplate.gradle, with the following message:

"Cannot change dependencies of dependency configuration ' ' after it has been resolved."

This error arises because, as of this update, dependencies that were previously placed in mainTemplate.gradle now need to be moved to settingsTemplate.gradle. Despite trying to resolve the issue by updating to HMS Unity Plugin versions 2.3.8 and 2.3.9, the problem persists. Manual changes to the generated hmsBaseProjectTemplate.gradle file have not helped, and neither has forcing the resolution through the External Dependency Manager.

Possible Cause: The issue seems to stem from a mismatch between the way dependency configurations are handled in Unity 2021.3.x versions and the latest Android API requirements. Specifically, modifications to dependency configurations after their resolution can lead to this build error. This may occur due to changes in how Unity generates and processes Gradle files in the context of Android builds, especially for newer Android API levels.

Recommendation: We suggest upgrading to a newer version of Unity beyond 2021.3.42f1, as this version may not fully support the latest Android build system requirements for API 34 (Android 14). Unity versions closer to 2022.x or beyond may offer better compatibility with updated Android APIs and resolve the dependency handling issue. Ensure that your HMS Unity Plugin is also updated accordingly to maintain compatibility.

Steps to Try:

Upgrade Unity to the latest Long Term Support (LTS) version beyond 2021.3.42f1, as newer versions may have addressed this dependency resolution issue. Ensure all templates (mainTemplate, settingsTemplate) are properly configured after the Unity update.

Please let us know if upgrading Unity resolves the issue, or if further assistance is required.

Aziz-T avatar Oct 17 '24 12:10 Aziz-T

@Aziz-T I tried to build in 2021.3.44f1 (latest), and error is still here

PromanSEW avatar Oct 17 '24 14:10 PromanSEW

2021.3.45f1 - the same error

PromanSEW avatar Oct 22 '24 05:10 PromanSEW

It looks like the issue has the same roots as EDMU has when Unity jumped to Gradle 7.x in 2021.3.41 (https://github.com/googlesamples/unity-jar-resolver/issues/699)

Unity has the same tooling for 2022.2+, and maybe it is a hint how to deal with this: as far as HMS plugin has proper setup for it's gradle templates for 2022.2+, we might want to find UNITY_2022_X defines (this is how HMS branches gradle files generation for Gradle 7.x and earlier versions) and add UNITY_2021_3_OR_NEWER (or UNITY_2021_3_42 alike, depends on Unity version) - by doing this we will turn on behaviour for gradle files generation as if we are in Unity 2022.2+

There are just 3 instances of UNITY_2022_3_OR_NEWER and UNITY_2022_2_OR_NEWER in HMS Editor assembly (1 in HMSGradleWorker and 2 in HMSGradleFixer), replacing them with, for example, UNITY_2022_3_OR_NEWER || UNITY_2021_3_OR_NEWER should do the trick.

I was able to build succesfully with this, but can't yet confirm whether it fails in runtime or not. I hope there will be others to try this and write here the result ahead.

Remstam avatar Oct 25 '24 14:10 Remstam

Tried to export project to Android Studio - got the same error;

Caused by: org.gradle.api.InvalidUserDataException: Cannot change dependencies of dependency configuration ':classpath' after it has been resolved.

PromanSEW avatar Oct 27 '24 10:10 PromanSEW

@Remstam I tried to replace UNITY_2022_X defines to UNITY_2021_3_OR_NEWER but no luck, the same error. Also, I found this, but cannot write needed code myself, here is maybe the solution: https://github.com/EvilMindDevs/hms-unity-plugin/blob/e3024162980710f82d2b2f8bf3a64974026d9266/Assets/Huawei/Editor/Utils/HMSGradleWorker.cs#L123-L127

PromanSEW avatar Oct 30 '24 10:10 PromanSEW

EmptyProjectHuawei.zip Here is an empty project to compare (2021.3.42) with Huawei plugin 2.3.9 installed and UNITY_2022_X defines updates. (Also I had to change package name to default in agconnect.json, otherwise the build fails with the appropriate message) Just switch to Android platorm and build, no additional manifest/gradle shenanigans needed (all the checkboxes in Project Settings -> Publishing Settings are empty).

@PromanSEW you could test this and maybe provide your minimal reprocase so it would be possible to track down the difference

Remstam avatar Oct 30 '24 11:10 Remstam

@Remstam Thanks, your project is able to build. But I use EDM4U and Firebase Crashlytics. I tried to build with them, but no luck. I got many errors, and fixed them all, except the last:

--E- get manifestOutputDirectory error
get manifestOutputDirectory error: Could not get unknown property 'manifestOutputDirectory' for task ':launcher:processReleaseManifest' of type com.android.build.gradle.tasks.ProcessMultiApkApplicationManifest.
ERROR:D8: com.android.tools.r8.kotlin.H
ERROR:D8: com.android.tools.r8.kotlin.H
....

Finally I decided just uninstall Crashlytics before build for AppGallery. I am tired for this shit.

PromanSEW avatar Oct 31 '24 09:10 PromanSEW

@Remstam Strange... I was able to build my project (not yours), with last Firebase. WTF is going on, why? I just replace defines as in your comment below

PromanSEW avatar Oct 31 '24 11:10 PromanSEW

Any one having this issue i have solved this by applying "apmsInstrumentationEnabled=false" this line in Assets/Plugin/Android/gradleTemplate file. It might look like this

"org.gradle.jvmargs=-XmxJVM_HEAP_SIZEM org.gradle.parallel=true apmsInstrumentationEnabled=false unityStreamingAssets=STREAMING_ASSETS ADDITIONAL_PROPERTIES "

muhammadali514 avatar Feb 18 '25 09:02 muhammadali514