- Home /
Gradle Build Error
After updating Unity to version 5.6.3p2, I am getting an error when Unity is "Building Gradle Project" when trying to build an .apk for android platform. This is what the console says;
CommandInvokationFailure: Gradle build failed. C:/Program Files (x86)/Java/jdk1.8.0_131\bin\java.exe -classpath "C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-2.14.jar" org.gradle.launcher.GradleMain "assembleRelease" stderr[ FAILURE: Build failed with an exception.
* What went wrong: A problem occurred configuring root project 'gradleOut'.
* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. ] stdout[ Incremental java compilation is an incubating feature.Cannot add task ':prepareUnityAdsLibrary' as a task with that name already exists.
BUILD FAILED
Total time: 26.887 secs ] exit code: 1
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) UnityEditor.Android.GradleWrapper.RunJava (System.String args, System.String workingdir, UnityEditor.Android.Progress progress) Rethrow as GradleInvokationException: Gradle build failed UnityEditor.Android.GradleWrapper.RunJava (System.String args, System.String workingdir, UnityEditor.Android.Progress progress) UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, UnityEditor.Android.Progress progress) UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) UnityEditor.HostView:OnGUI()
After updating, I was having trouble with Untiy Ads. I was getting compiler errors concerning the Header File Advertisements. Turns out that for some reason after updating, Unity Ads was turned off or not connected to my project and could not reference that header. So I tried to update though the asset store only to have more problems. Then I learned that the latest version of the Ads plug-in is automatically added with newer version of Unity and I didn't need to download through the Asset store. In fact doing so causes conflicts. I deleted the plug-in I downloaded from the asset store and reloaded and reconnected Unity Ads through the services tab but the problem still persists.
What should I do to solve this issue ? Thanks In advance.
It appears that you might have 2 copies of the Unity ads libraries in your project (one may be automatically added by the "Services" tab, and another one probably included as a file in your project).
Answer by Devster2020 · Feb 18, 2018 at 12:58 PM
@GODSPIRIT @thedefiancerebels @PouyaAR @Retz_Retro That's because you have probably import UnityADS from Asset store and also checked the "Enable built-in Ads extension" in the "Services" -> "Unity ADS" -> "Advanced" Unchecking that option tell unity to use the package downloaded from asset store, et voilà.. Build with gradle comes back to work correctly ^^
WOR$$anonymous$$ING NOW! Thanks a lot! This helped a lot. I actually deleted the Assets from the project folder. So the problem seems to be that some definitions were duplicated this way.
Thanks!
THIS WOR$$anonymous$$S!
I have spent almost two weeks by searching solution (changing scripts, re/importing plugins, installing and analyzing logs by android studio, installing various SD$$anonymous$$ versions, searching on web and try/error...) ... endless frustration on my side... and the solution was as easy as you wrote....!
THAN$$anonymous$$ YOU !!!
Answer by Big-Ed · May 28, 2018 at 01:18 PM
I have the same issue Cannot add task ':prepareUnityAdsLibrary' as a task with that name already exists. \Assets\Plugins\Android\unity-ads.aar \Assets\Plugins\Android\UnityAds.aar I imported the new Unity Ads and got the conflict because I have 2 unity ads aar in the plugins android directory that are conflicting and don't know which one to use.
I removed unity-ads.aar and I can compile now.
Does anyone know if the new UnityAds.aar from the asset store works with AdMob mediation?
UnityAds.aar I believe is packaged with Unity Ads from the asset store and the other unity-ads.aar is from integration with AdMob mediation. I decided to move away from AdMob mediation for the GDPR stuff going on and use Unity Ads directly.
Answer by Retz_Retro · Feb 15, 2018 at 09:44 PM
I was met with the exact same error. I found that UnityAds was being accessed twice. Once within my UnityAds folder within Assets and again within my Plugins/Android folder within Assets. I selected one of the UnityAds.aar files and unchecked Android from the Include Platforms heading, this fixed this issue for me.
Hope it helps.