I'm trying to compile my project using "Build App Bundle (Google Play)" for the first time. However I am getting an error while merging dex archives
.
I believe it is due to some of my plugins are using different version of some amazon module
first error printed in the console:
D8: Program type already present: com.amazon.ags.BuildConfig
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
When I search for com.amazon.ags.BuildConfig
I find nothing. (But my assumption might be wrong)
I have tried to enable multiDex by adding the mainTemplate.gradle
to my project
defaultConfig {
minSdkVersion **MINSDKVERSION**
targetSdkVersion **TARGETSDKVERSION**
applicationId '**APPLICATIONID**'
multiDexEnabled true
ndk {
abiFilters **ABIFILTERS**
}
versionCode **VERSIONCODE**
versionName '**VERSIONNAME**'
}
But I'm still getting the same error, and I have no chance of knowing whether the new gradle file is actually included when building or if unity simply ignores it.
This is the error that pops up when the build fails:
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
C:\Users\path-to-project\unity\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\57,
C:\Users\path-to-project\unity\Temp\gradleOut\build\intermediates\transforms\externalLibsDexMerger\release\0,
C:\Users\path-to-project\unity\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\52.jar,
C:\Users\path-to-project\unity\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\54.jar
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
I see a lot of people lately solving similar error by removing unity ads and/or google ads plugins and re-enable them, I never used google ads, but I have tried to remove unity ads plugin, still no cigar, I have also tried with different version of the unity ads plugin both the one from asset store and the "built in extension" still no dice.
I have been on a discussion with some guys here but I have tried the solutions each one of them have provided without luck.
Any suggestions on how I can find out which plugin is causing this and how to fix it ?
For some reason when choosing gradle build these two are not automatically toggled, and maybe in some cases they don't have to be. But setting minify to Gradle (experimental) completely resolved all the build errors I was getting after updating unity.
Go to player settings > Project Settings > Minify, in there, there will be an option of Release, set it to Gradle . For some reason when choosing gradle build these two are not automatically toggled, and maybe in some cases they don't have to be.
Turns out that with the newer version of unity there is a few more options in the publish settings that needs to be set! Go to player settings > Project Settings > Minify, in there, there will be an option of Release, set it to Gradle .
I have lately been experimenting with choosing Proguard instead of the experimental Gradle minifier (can be selected in the dorpdown as well). When configured correctly proguard will also resolve your DEX limitation errors, and get rid of unused code and even compress your build size even more.
Someone in the thread from unity forum finally posted a working solution. I'm gonna share it here as well so hopefully everyone who lands on the question with this issue will not have to spend 30 hours blindfolded resolving dex merging conflicts like I did.
Turns out that with the newer version of unity there is a few more options in the publish settings
that needs to be set!
quoting RealPpTheBest s' answer
Go to player settings > Project Settings > Minify, in there, there will be an option of Release, set it to Gradle .
For some reason when choosing gradle build these two are not automatically toggled, and maybe in some cases they don't have to be. But setting minify to Gradle (experimental)
completely resolved all the build errors I was getting after updating unity.
EDIT: september-2019 - Solution above should still work, but:
I have lately been experimenting with choosing Proguard
instead of the experimental Gradle minifier (can be selected in the dorpdown as well). When configured correctly proguard will also resolve your DEX limitation errors, and get rid of unused code and even compress your build size even more.
This post has a quite throughly detailed guide on how to enable and configure it. Keep in mind though, that the configuration will be unique to which dependencies you are using, so you will have to read up and do some custom configuration here most likely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With