Problems with Building Exported Android project with Unity Ads

I think the title of my last post was too detailed or unclear, so I made the title more clear.

I started a thread about a Gradle build with UnityAds,

But even if I didn’t get Gradle working, I still get an error when using the .idea project.

I’m fine with getting either a Gradle build or .idea build working.

I’m prepared to re-iterate all of the steps I’ve attempted in the past couple of weeks if someone is willing to help investigate, since following the related threads is fairly confusing at this point.

Thanks for any help or suggestions people have!

Hi. Assuming you are building for Android using Android Studio or IntelliJ?

Can you send us a simple repro project, which shows the problem you are experiencing? My test project using the native Android SDK compiles fine using Android Studio/Gradle.

Thanks, Rasmus

Hi Rasmus,

Thanks for responding. I’m using Android Studio and building with Android API 21.

I should have noted that I can build the project fine as well when imported as a Gradle project. But, when I try to launch on my device, I get the exception:

The full output is below:

AGPBI: {“kind”:“SIMPLE”,“text”:“UNEXPECTED TOP-LEVEL EXCEPTION:”,“position”:{},“original”:“UNEXPECTED TOP-LEVEL EXCEPTION:”}
AGPBI: {“kind”:“SIMPLE”,“text”:“com.android.dex.DexException: Multiple dex files define Lcom/unity3d/ads/android/BuildConfig;”,“position”:{},“original”:“com.android.dex.DexException: Multiple dex files define Lcom/unity3d/ads/android/BuildConfig;”}
AGPBI: {“kind”:“SIMPLE”,“text”:“\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)”,“position”:{},“original”:“\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)”}
AGPBI: {“kind”:“SIMPLE”,“text”:“\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)”,“position”:{},“original”:“\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)”}
AGPBI: {“kind”:“SIMPLE”,“text”:“\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)”,“position”:{},“original”:“\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)”}
AGPBI: {“kind”:“SIMPLE”,“text”:“\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)”,“position”:{},“original”:“\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)”}
AGPBI: {“kind”:“SIMPLE”,“text”:“\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:189)”,“position”:{},“original”:“\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:189)”}
AGPBI: {“kind”:“SIMPLE”,“text”:“\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)”,“position”:{},“original”:“\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)”}
AGPBI: {“kind”:“SIMPLE”,“text”:“\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)”,“position”:{},“original”:“\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)”}
AGPBI: {“kind”:“SIMPLE”,“text”:“\tat com.android.dx.command.dexer.Main.run(Main.java:246)”,“position”:{},“original”:“\tat com.android.dx.command.dexer.Main.run(Main.java:246)”}
AGPBI: {“kind”:“SIMPLE”,“text”:“\tat com.android.dx.command.dexer.Main.main(Main.java:215)”,“position”:{},“original”:“\tat com.android.dx.command.dexer.Main.main(Main.java:215)”}
AGPBI: {“kind”:“SIMPLE”,“text”:“\tat com.android.dx.command.Main.main(Main.java:106)”,“position”:{},“original”:“\tat com.android.dx.command.Main.main(Main.java:106)”}

FAILED

FAILURE: Build failed with an exception.

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

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘C:\Program Files\Java\jdk1.7.0_25\bin\java.exe’’ finished with non-zero exit value 2

I do not get this error when I build and launch an exported Unity Android project without Unity Ads.

While trying to prepare a test build for UT, I was actually able to figure it out. I must have been setting up the project wrong in Android Studio, so I apologize for causing any wasted time for UT.

I think my problem was that I was not using File > New > Import Project… so that it creates the appropriate Gradle make files. I certainly must have done that with my earlier tests, since I got them to work, but I think my frustration and repetition wore me down that I lost some focus towards solving the problem.

Thanks for Unity Technologies’ responsiveness anyway.

1 Like