Search Unity

  1. We would like to hear your feedback about Unity and our products. Click here for more information.
    Dismiss Notice

Unity ads - Build error

Discussion in 'Android' started by minh23520000, Feb 21, 2018.

  1. minh23520000

    minh23520000

    Joined:
    Feb 2, 2018
    Posts:
    2
    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".
    upload_2018-2-21_22-13-18.png
    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.Action`1 progress, System.String error)
    UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 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
     
  2. minh23520000

    minh23520000

    Joined:
    Feb 2, 2018
    Posts:
    2
    Anyone? Thanks =))
     
  3. gamerkendall

    gamerkendall

    Joined:
    Feb 24, 2017
    Posts:
    2
    I hav faced this issue too. Have you resolved it ?
     
  4. AndresSepulveda

    AndresSepulveda

    Joined:
    Mar 12, 2014
    Posts:
    52
    Same Here....
     
  5. Aiviator3

    Aiviator3

    Joined:
    Jun 26, 2014
    Posts:
    3
    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.
     
    Last edited: May 9, 2018
  6. NEVER-SETTLE

    NEVER-SETTLE

    Joined:
    Apr 22, 2018
    Posts:
    29
    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!
     
  7. msaffold805

    msaffold805

    Joined:
    Apr 30, 2018
    Posts:
    1
    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?
     
  8. unity_orFC2K8kG2EwQA

    unity_orFC2K8kG2EwQA

    Joined:
    Oct 8, 2018
    Posts:
    2
    upload_2018-11-14_7-18-19.png

    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.
     
  9. anileapen05

    anileapen05

    Joined:
    Jun 8, 2013
    Posts:
    14
    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!
     
  10. bahaeddine666

    bahaeddine666

    Joined:
    Apr 3, 2019
    Posts:
    9
    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 !!