googleads-mobile-unity: Cannot change resolution strategy of dependency configuration ':unityLibrary:aarArtifacts' after it has been resolved.

[REQUIRED] Step 1: Describe your environment

  • Unity version: 2020.3.37f1
  • Google Mobile Ads Unity plugin version: 8.6.0
  • Platform: Android
  • Platform OS version: Android 13
  • Any specific devices issue occurs on: N/A
  • Mediation ad networks used, and their versions: _____

[REQUIRED] Step 2: Describe the problem

Steps to reproduce:

When targeting API 34 in Unity, I’m seeing the the following error while making a build. I have enabled both the options as mentioned here https://github.com/googleads/googleads-mobile-unity/issues/2930#issuecomment-1817271448


FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':unityLibrary'.
> Cannot change resolution strategy of dependency configuration ':unityLibrary:aarArtifacts' after it has been resolved.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 29 (3 by maintainers)

Most upvoted comments

You can easily fix this issue by adding these lines to your mainTemplate.gradle:

gradle.projectsEvaluated {
    apply from: 'GoogleMobileAdsPlugin.androidlib/validate_dependencies.gradle'
}

I had same problem as you guys and fixed it by steps below:

Unity version is 2021.3.26f1 GoogleMobileAds 8.7 Chartboost mediation 9.6.0. Min Api android 22 (5.1) Target API 34

Follow google document linked below like this: https://developers.google.com/admob/unity/gradle

1- download gradle version 6.7.1 binary file here: https://gradle.org/next-steps/?version=6.7.1&format=bin

2- Extract it anywhere and make unity use this one instead of default gradle installed with the editor.

3- In android player settings check custom “base” gradle template and not “main” gradle temple nor custom gradle properties.

4- Open the Assets/Plugins/Android/baseProjectTemplate.gradle file and set the dependencies to use Gradle build tools 4.2.0. buildscript { dependencies { classpath 'com.android.tools.build:gradle:4.2.0' **BUILD_SCRIPT_DEPS** } }

5- Force resolve your project using External dependency manager 1.2.177 and it should resolve successfully.

6- Make sure to check Use R8 in minify code section if needed and to not check release which causes other errors.

7- lastly from build menu press clean build which is under build button itself.

Hope this helps.

I have it here:

// Android Resolver Exclusions Start
android {
  packagingOptions {
      ...
  }
}

// GMA
gradle.projectsEvaluated {
    apply from: 'GoogleMobileAdsPlugin.androidlib/validate_dependencies.gradle'
}

// Android Resolver Exclusions End
android {
    compileSdkVersion **APIVERSION**
    buildToolsVersion '**BUILDTOOLS**'
    ...
}**REPOSITORIES**
**IL_CPP_BUILD_SETUP**
**SOURCE_BUILD_SETUP**
**EXTERNAL_SOURCES**

You can easily fix this issue by adding these lines to your mainTemplate.gradle:

gradle.projectsEvaluated {
    apply from: 'GoogleMobileAdsPlugin.androidlib/validate_dependencies.gradle'
}

Where?? I’m anxious seeing so many people get their issue solved by adding this, but I have no idea where to put this in my mainTemplate.gradle file. Below everything? In an android backet? In the dependencies section? Where?? 😢

I tried in many places but the problem persists. Maybe I’m putting it in the wrong spot.

Hi everyone,

Confirming this is an issue and we are looking into a fix.

I was getting this error after updating from a very old version of Unity Google Mobile Ads to 8.7.0.

I fixed it by deleting the Assets\GoogleMobileAds\ folder and deleting all the googlemobileads files and folders (upper and lower case) in \Assets\Plugins\Android.

I then reinstalled the 8.7.0 package, force resolved all Android dependencies, and Android builds succeeded again.

Perhaps some old Google Ads settings or files from prior versions were still in the project and were breaking the build, but this fixed it for me.

Thank you @AlirezaTabasi7, it works. Unity 2020.3.48f1 Plugin 8.7.0 Api level min 21 Target 33 It didn’t work until I unchecked custom main gradle temple and custom gradle properties I don’t use R8 minify, if I do the app shows only a black screen on my tablet (android 6.0)

https://developers.google.com/admob/unity/gradle

@NVentimiglia it isn’t fixed. I have the same issue with the proposed workaround: `FAILURE: Build failed with an exception.

  • Where: Script ‘E:\UnityProjects\project\Library\Bee\Android\Prj\IL2CPP\Gradle\unityLibrary\GoogleMobileAdsPlugin.androidlib\validate_dependencies.gradle’ line: 23

  • What went wrong: A problem occurred evaluating script.

Cannot change dependencies of dependency configuration ‘:unityLibrary:aarArtifacts’ after it has been resolved.`

Unity 2021.3.34 Target API Level 34 - gives error upon build. Target API Level 33 - builds w/o errors.

You can easily fix this issue by adding these lines to your mainTemplate.gradle:

gradle.projectsEvaluated {
    apply from: 'GoogleMobileAdsPlugin.androidlib/validate_dependencies.gradle'
}

OMG thanks you so much. It works for me.

This should be included in GoogleMobileAds v 8.6.0.

You may also try clearing your gradle cache.

Got the same issue when implemented Google Admob version 8.6.0 and com.google.android.gms:play-services-ads:22.5.0 on Unity 2021.3.18. Any way to fix it