I have been trying to export an Google Android Project from Unity so I can integrate an external library with Gradle.
I am using :
Unity 5.4 Beta 18 OSX
Android Studio 2.1.1
I had first attempted to use Unity 5.3.4 & 5.3.5 but it was crashing on launch in what appeared to be an issue with the Unity IAP export when building a Google Android Project. A bit of research lead me to believe that the issue was resolved in the latest 5.4 Beta, however now I am getting a Multiple define error when building.
Something signigant has changed as now I have a googleAIDL, googlePlay, and unity adsrelease folders.
Error:Execution failed for task â:cupcakeDigital:transformClassesWithDexForDebugâ.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process âcommand â/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/javaââ finished with non-zero exit value 2
When trying to remove this particular class it just moved onto the next one and repeat the error again. Is this a Unity issue with IAP and Ads or could this be something specific with my project?
If I build just to an APK from Unity it works fine but then i cannot implement the external SDK. I can also export a test scene without Ads or IAP enabled and it does work in Project. I will try and enable those next to see if it is specifically these addons.
After a few more tests on a fresh project I have confirmed that once you turn on Unity IAP in the services panel this error will occur in your google android project. These last few tests were with Unity 5.3.5p1 and 5.4.0b20.
I will file a bug and in the meantime try and find a workaround.
Iâm not using Unity IAP, I get this
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
@tanveerm , that would have actually no impact. This class is auto-generated and contains information about the configuration(tools versions) of the build. @Yury-Habets , Iâm not using Unity IAP. But, I have: Facebook, OpenIAB, Fyber, Helpshift, NativeLibrary and a couple more plugins in the project.
The temporary solution for me(as I really need to have all my plugins in the project) was to remove BuildConfig class from the .jars with the help of WinRar.
This worked for me too, thank you! I just searched the whole project structure exported from Unity for â*.jarâ and then just searched for BuildConfig class in every .jar file and deleted every occurence. Then I imported and built my project in AndroidStudio, and it worked, no more exceptions.
@Qbit88@andyisbonza@tanveerm We suspect the Unity 5.3-era Exporterâs transformation of the Java archives (AARs) made it more likely to see a duplicate symbol build problem later in this caseâs build pipeline.
Weâre not planning on stripping the BuildConfig classes, currently: Unity IAP does include a BuildConfig.class in some of its AARs and another copy seems to have been injected somewhere in the 5.3/5.4-era âADTâ (considering retiring this soon) exporter, or possibly by a latter phase in the build toolchain after Unity. (Thanks to @Sebrofjr for the repro detail in his case.)
I believe a resolution can be found in Unity 5.5âs âGradle exportâ (versus the 5.3-era âADT exportâ). It could resolve this particular duplicate class vulnerability since there is no transformation of the AARs; they are kept intact as the sole source of these Java classes for the latter steps of the build chain, Android Studio in this case.
Also, the workaround of performing a kind of âZIP surgeryâ on the classes.jar enclosed within the various AARs and stripping the BuildConfig.class, should also still work. I believe this would be unnecessary with Unity 5.5âs Gradle export however.
Iâve hit this issue exactly migrating from âBuild System: Internal (Default)â to âBuild System: Gradle (New)â (with no export at first). I have not tried âBuild System: ADT (Legacy)â. Unity 5.5.4f1.
As said before, removing BluildConfig from the Unity jar solves the issue.
In my case, the conflict started after adding the Kochava SDK.
On a mac, you do it like this:
# Removing duplicated class [B]BuildClass[/B]
# List classes from JAR files
$ cd Assets
$ find . -name '*.jar' -exec grep -Hls BuildConfig {} \;
./Plugins/Android/GoogleMobileAdsPlugin/libs/unity-plugin-library.jar
./Plugins/Android/KochavaSDK.jar
# Remove class
$ zip -d ./Plugins/Android/GoogleMobileAdsPlugin/libs/unity-plugin-library.jar "*/BuildConfig.class