Unity ads - Build error

Hi, I just integrate Unity ads and try to export my game to android platform and got this error: (My game run and export completely normal before adding unity ads).
“com.android.build.api.transform. TransformException: com.android.ide.common.process. ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/unity3d/ads/BuildConfig; See the Console for detail”.


Here’s the detailed problem:
CommandInvokationFailure: Gradle build failed.
C:\Program Files\Java\jdk1.8.0_161\bin\java.exe -classpath “C:\Program Files\Unity 2018.1.0b4\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.0.1.jar” org.gradle.launcher.GradleMain “-Dorg.gradle.jvmargs=-Xmx2048m” “assembleRelease”

stderr[

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:transformClassesWithDexForRelease’.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/unity3d/ads/BuildConfig;

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED in 15s
]
stdout[
NDK is missing a “platforms” directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to C:\Users\HP\AppData\Local\Android\android-sdk\ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.

NDK is missing a “platforms” directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to C:\Users\HP\AppData\Local\Android\android-sdk\ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.

The setTestClassesDir(File) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the setTestClassesDirs(FileCollection) method instead.
The getTestClassesDir() method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the getTestClassesDirs() method instead.
The ConfigurableReport.setDestination(Object) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the method ConfigurableReport.setDestination(File) instead.
:preBuild UP-TO-DATE
:preReleaseBuild UP-TO-DATE
:checkReleaseManifest
:preDebugBuild UP-TO-DATE
:prepareAdmoblibReleaseLibrary
:prepareAppcompatV72610Library
:preparePlayServicesAds1180Library
:preparePlayServicesAdsLite1180Library
:preparePlayServicesBasement1180Library
:preparePlayServicesGass1180Library
:prepareSupportCompat2610Library
:prepareSupportV42610Library
:prepareUnityAdapter2100Library
:prepareUnityAdsLibrary
:prepareUnityAdsSdk21Library
:GoogleMobileAdsPlugin:preBuild UP-TO-DATE
:GoogleMobileAdsPlugin:preReleaseBuild UP-TO-DATE
:GoogleMobileAdsPlugin:checkReleaseManifest
:GoogleMobileAdsPlugin:prepareReleaseDependencies
:GoogleMobileAdsPlugin:compileReleaseAidl
:GoogleMobileAdsPlugin:compileReleaseNdk NO-SOURCE
:GoogleMobileAdsPlugin:compileLint
:GoogleMobileAdsPlugin:copyReleaseLint NO-SOURCE
:GoogleMobileAdsPlugin:mergeReleaseShaders
:GoogleMobileAdsPlugin:compileReleaseShaders
:GoogleMobileAdsPlugin:generateReleaseAssets
:GoogleMobileAdsPlugin:mergeReleaseAssets
:GoogleMobileAdsPlugin:mergeReleaseProguardFiles UP-TO-DATE
:GoogleMobileAdsPlugin:packageReleaseRenderscript NO-SOURCE
:GoogleMobileAdsPlugin:compileReleaseRenderscript
:GoogleMobileAdsPlugin:generateReleaseResValues
:GoogleMobileAdsPlugin:generateReleaseResources
:GoogleMobileAdsPlugin:packageReleaseResources
:GoogleMobileAdsPlugin:processReleaseManifest
:GoogleMobileAdsPlugin:generateReleaseBuildConfig
:GoogleMobileAdsPlugin:processReleaseResources
:GoogleMobileAdsPlugin:generateReleaseSources
:GoogleMobileAdsPlugin:incrementalReleaseJavaCompilationSafeguard
:GoogleMobileAdsPlugin:javaPreCompileRelease
:GoogleMobileAdsPlugin:compileReleaseJavaWithJavac
:GoogleMobileAdsPlugin:processReleaseJavaRes NO-SOURCE
:GoogleMobileAdsPlugin:transformResourcesWithMergeJavaResForRelease
:GoogleMobileAdsPlugin:transformClassesAndResourcesWithSyncLibJarsForRelease
:GoogleMobileAdsPlugin:mergeReleaseJniLibFolders
:GoogleMobileAdsPlugin:transformNativeLibsWithMergeJniLibsForRelease
:GoogleMobileAdsPlugin:transformNativeLibsWithSyncJniLibsForRelease
:GoogleMobileAdsPlugin:bundleRelease
:prepareReleaseDependencies
:compileReleaseAidl UP-TO-DATE
:compileReleaseRenderscript UP-TO-DATE
:generateReleaseBuildConfig UP-TO-DATE
:generateReleaseResValues UP-TO-DATE
:generateReleaseResources UP-TO-DATE
:mergeReleaseResources UP-TO-DATE
:processReleaseManifest
:processReleaseResources
:generateReleaseSources
:incrementalReleaseJavaCompilationSafeguard UP-TO-DATE
:javaPreCompileRelease
:compileReleaseJavaWithJavac UP-TO-DATE
:compileReleaseNdk NO-SOURCE
:compileReleaseSources UP-TO-DATE
:lintVitalRelease
:mergeReleaseShaders UP-TO-DATE
:compileReleaseShaders UP-TO-DATE
:generateReleaseAssets UP-TO-DATE
:mergeReleaseAssets
:transformClassesWithDexForRelease FAILED
51 actionable tasks: 41 executed, 10 up-to-date
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action1 progress, System.String error) UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action1 progress)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 progress)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()

Does anyone know how to fix this problem? I’m using Unity 2018.1.0b4 on Window 10 - 64 bit
Thanks

Anyone? Thanks =))

I hav faced this issue too. Have you resolved it ?

Same Here…

I also have this issue, running unity 2018.1.0f2. Did anyone solve it?

EDIT :
I solved it by removing an clashing lib from the plugins directory.

Unity ads? Don’t you mean AdMob (Google ads) ?
Anyway, same issue here. For me I guess it happened because I moved the GoogleMobileAds folder form the root (Assets) folder to Plugins and messed around with other folders there too because I didn’t like the structure.
In the end I couldn’t recover from the error and I just deleted the whole AdMob plugin and imported it again, works like a charm!

To fix this, I disabled the built-in unity ads extension under the unity ads service advanced settings, but left the unity ads enabled. Download and import monetization 3.0 or whatever the latest unity ads implementation is from asset store. Now it builds successfully, but the test ad only shows in the editor. Perhaps this will stop when I disable test mode?

Disable this and it will work perfectly… Do note the warning message shown by unity, so if you have downloaded asset package Unity Monetization 3.0 directly from the asset store than it will work fine.

I am yet to try if my ads are showing up in production.

12 Likes

This worked for me
credit to: https://www.spikything.com/blog/ind…ror-with-unityads-after-upgrading-to-unity-5/

  • Close Unity Editor
  • Backup your project
  • Remove any folder or meta file called UnityAds from your project’s Assets/Libs folder
  • Remove any folder or meta file called UnityAds from your project’s Assets/Plugins/Android folder
  • Start Unity
  • Build your project for Android

If this doesn’t work, try doing an Assets > Reimport All, then building again. Hopefully, future version of Unity will solve this problem automatically. Good luck out there!

This actually works for me, if you think about it, it’s so logical, why would you enable Build in ads extension while you are actually using unity monetization !!

This worked for me too !!!

It actually works! @bahaeddine666 will the ads work you put the game out on the play store?

it worked for me

They worked for me too! Wish i had a million downloads though

check out my game
https://play.google.com/store/apps/details?id=com.OhbStudio.Ma3

Thank you so much

If still anyone out there couldn’t fix the issue, here is my situation:

I implemented Google Admob to my game years ago. A few days ago I deleted all the code about Admob and implemented Unity Ads and after that I couldn’t get any build.

I fixed it by just deleting plugins folder.

.!! Please back up your game if you are thinking about doing the same as me !!