googleads / googleads-mobile-unity

Official Unity Plugin for the Google Mobile Ads SDK
https://developers.google.com/admob/unity
Apache License 2.0
1.34k stars 1.08k forks source link

Cannot change resolution strategy of dependency configuration ':unityLibrary:aarArtifacts' after it has been resolved. #3042

Closed kushG closed 4 months ago

kushG commented 6 months ago

[REQUIRED] Step 1: Describe your environment

[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.
Heathclliff commented 6 months ago

I was getting a similar problem. There are 2 solutions:

  1. many rebuilds of native Android libraries inside the Admob plugin;
  2. upgrade Unity to version 2022.3.
thiagolr commented 6 months ago

I also have the same problem, any idea how to solve it?

SuperUnityCoder commented 6 months ago

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

gradle.projectsEvaluated {
    apply from: 'GoogleMobileAdsPlugin.androidlib/validate_dependencies.gradle'
}
NVentimiglia commented 6 months ago

This should be included in GoogleMobileAds v 8.6.0.

You may also try clearing your gradle cache.

lhchi commented 5 months ago

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

davutint commented 5 months ago

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

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

this is work for me, thanks a lot <3

tonismogames commented 5 months ago

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

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

Thank You o great wizard this fixed the problem

Suraj-SPG commented 5 months ago

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

I'm also facing same issue. Any update ? Not using custom mainTempate.gradle

Google Mobile Ads Unity plugin version: 8.6.0

Watcher3056 commented 5 months ago

+1 get this issue. This fix does not help me. Sometimes it lets me to make one build and then stops me from building again with that error.

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

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

Unity 2021.3.29f1

UPD: It lets me build once when I change gradle to external or back to internal

LeonardoDemartino commented 5 months ago

I'm having this issue as well. Unity 2021.3.27f1 Google Mobile Ads Unity 8.6.0

vincent-savysoda commented 5 months ago

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

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

I can't update the mainTemplate.gradle as its currently disabled for me as i use a custom gradleTemplate. Is there something i need to do to replicate the same thing in this scenario?

NVentimiglia commented 5 months ago

Hi,

We are looking into this issue.

gheatgheat commented 5 months ago

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.

shefich commented 4 months ago

After this workaround I still have this errors in console: `stderr[ Note: E:\xxx\xxx\Library\Bee\Android\Prj\IL2CPP\Gradle\unityLibrary\src\main\java\com\unity3d\player\UnityPlayerActivity.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.

2: Task failed with an exception.

Can you help me to fix them? Unity 2021. Unity 2022 fix the issues, but it's not an option.

NVentimiglia commented 4 months ago

Hi everyone,

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

ga0357r commented 4 months ago

I managed to solve the issue by upgrading unity to 2022.3. See Google documentation

Ckuruuzum commented 4 months ago

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

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

He is a magician

dungpt14083 commented 4 months ago

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

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

Thank you so much, it took me 3 days to fix it

shefich commented 4 months ago

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

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

Abulero commented 4 months ago

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.

SuperUnityCoder commented 4 months ago

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**
vincent-savysoda commented 4 months ago

I'm still having this issue in the latest update :/

Unity 2021.3.33f1

evolutionsofgame commented 4 months ago

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

it work in google mobile ads 8.6, but in version 8.7, it can not fix. how to fix?

raft75 commented 4 months ago

Unity 2020.3.48f1

Same here, the following workaround was working in 8.60 but does not work in 8.70

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

AlirezaTabasi7 commented 4 months ago

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.

raft75 commented 4 months ago

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

kevinhtt commented 2 months ago

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.

raulseixasbr commented 2 months ago

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

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

Worked like a charm, but only after downgrading to 8.6.0. Couldn`t make 8.7.0 work...

2345678910JQKA commented 2 months ago

https://github.com/googleads/googleads-mobile-unity/issues/3042#issuecomment-1919833720 I updated the android sdk to 34 and solved the problem with this