Unity Build Error when adding GoogleMobileAds v3.13.1.unitypackage

1,524 views
Skip to first unread message

A Bones

unread,
Dec 17, 2019, 12:46:33 AM12/17/19
to Google Mobile Ads SDK Developers
Hello,

I am on WIn 10, running Unity vers 2017.4.301f
I have been successfully compiling 64bit aab files using IL2CPP for several weeks now, 
Using gradle default builder, not experimental, with no custom gradle template.

I have one asset, Cross Platform Native Plugins, which is used for Google Play Game services, 
and GooglePlayGPlugin-0.9.50/. unitypackage is also installed, both have been working fine, and have successfully compiled 64 bit aab files for Google Play.

Today I installed GoogleMobileAds v3.13.1.

I am getting a Build Failed on android build attempts.

Here is the log entry:

CommandInvokationFailure: Gradle build failed.
C
:/Program Files/Java/jdk1.8.0_111\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2017.4.30f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.6.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "bundleRelease"


stderr
[
D8
: Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver





FAILURE
: Build failed with an exception.


* What went wrong:
Execution failed for task ':transformDexArchiveWithExternalLibsDexMergerForRelease'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
C
:\Users\Andy \Documents\Unity 2017.4.301\ Drone\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\0.jar,
C
:\Users\Andy \Documents\Unity 2017.4.301\Drone\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\1.jar,

...repetitive entries truncated...the list goes all the way up to ...\release\135.jar

Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
 
Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver



This combination of assets has been used previously on my other apps of mine with no issues.

I have read the link
which appears in the error above, which is only for Android Studio users and does not apply.

I have read multiple forums on Unity, referring to similar errors based on duplicate NDK installations, and I only have NDK r13 installed, so most of those solutions did nothing to help me.

I have tried many solutions for the "MultiDex" errors, including using Gradle experimental build options, which causes the app to build fine, but app crashes on start on any android device.


I believe this is due to duplicate class entries in some of the asset libraries, possibly google game services, but I cannot find any duplicates.

I located this file to check for duplicates:, and screenshot 3 attached shows the contents of this folder
android.support.v4.os.ResultReceiver$MyResultReceiver

I can't see any indication of dupe files needing deletion.

I have reached the end of my wits a google-fu abilities. If anyone can assist, I would greatly appreciate any suggestions.

Thank you.




Gradle Error Capture.JPG
Gradle Error Capture2.JPG
Capture.3JPG.JPG

Mobile Ads SDK Forum Advisor Prod

unread,
Dec 17, 2019, 2:47:44 AM12/17/19
to 54bone...@gmail.com, google-adm...@googlegroups.com

Hi Andy,

 

Thank you for reaching out to us, and for giving an extensive rundown of your concern.

 

My first guess on why this would happen would be the presence of duplicate classes from the different .unitypackages you are currently using on your project. I'll be able to assist you on this if you could provide me the details below (via Reply privately to author):

  • Copy of your project folder
  • Special instructions for building the project, if any

 

You may opt to not include the Library and Temp folders when sending your project folder in order to reduce overall size. You may also share the project via Google Drive (or any other file-sharing service of your preference), as long as it's done privately.

 

Regards,

Ziv Yves Sanchez

Mobile Ads SDK Team



ref:_00D1U1174p._5001UOEhWc:ref

A Bones

unread,
Dec 17, 2019, 1:14:46 PM12/17/19
to google-adm...@googlegroups.com
I sent the files requested privately.

It may be important to note, that I was able to find several solutions to get it to build, but the resulting app downloaded from GPlay store crashes on start for all the solutions I have tried. I attempted all of these, which resulted in successful build, but app crashes:

-Updating another asset to support androidx libraries to eliminate multi dex errors
-Updating google play game services android resolver
-Building with grade - experimental build options
-Uninstalling NDK from Android studio, using only NDK r18 manually installed


All produced aab files, which resulted in a crashing app on start.

Mobile Ads SDK Forum Advisor Prod

unread,
Dec 18, 2019, 12:14:39 AM12/18/19
to 54bone...@gmail.com, google-adm...@googlegroups.com

Hi there,

 

Thank you for providing the requested details in private, as well as for giving additional context on your concern.

 

I can confirm that the Play Services Resolver tries to include AndroidX dependencies into the project whenever I imported the AdMob SDK unitypackage into it. While I was unable to determine why it does this (considering that version 3.13.1 of the AdMob SDK does not use AndroidX libraries yet), I was able to make an APK via simply excluding the AndroidX libraries from the build. Kindly see attached screenshot. I can confirm that the built APK then runs successfully on our test device, after setting up the App ID to be used by the AdMob SDK. Do note that this is the older (now deprecated) way of adding your AdMob App ID into your app; newer versions of the SDK has a different way of doing it.

 

A couple of additional notes here:

  • I noticed that your project is using rather old versions of the Unity engine, as well as old versions of the plugins themselves (including the AdMob SDK). While I understand that updating would take time and effort, I would still highly suggest you do the same in order to mitigate compatibility issues, especially with regard to AndroidX - Android Support Library incompatibilities.
  • The reason I built an APK (instead of an AAB as you've done for your project) is so that I can immediately test your build in our test device. I believe that the results should still be the same if I attempted to build an AAB instead.
  • I did try a couple of other (unsuccessful) solutions as well, including Gradle hacks, and importing to Android Studio, before realizing that this particular version of the AdMob SDK should not even be using AndroidX dependencies yet, as per the release notes. The migration to AndroidX only happened to version 3.18 and above.
exclude_androidx.png

A Bones

unread,
Dec 18, 2019, 1:57:12 AM12/18/19
to Google Mobile Ads SDK Developers
I too have tried the latest version GoogleMobileAds 4.10.0 and was able to build.

However, the app crashes on MobileAds.Initialize, stating that I did not define unitID and banner size, which I do in code.

A Bones

unread,
Dec 18, 2019, 2:00:49 AM12/18/19
to Google Mobile Ads SDK Developers
I can try your solution of exlcuding libraries, should I use the old GoogleMobileAds 3.13.0, or use the latest 4.10.0 ??

A Bones

unread,
Dec 18, 2019, 2:43:33 AM12/18/19
to Google Mobile Ads SDK Developers
I did what you stated, and my app can build now as APK,
but it crashes on app start.



On Tuesday, December 17, 2019 at 9:14:39 PM UTC-8, mobileadssdkforumadvisor wrote:

Mobile Ads SDK Forum Advisor Prod

unread,
Dec 18, 2019, 4:53:27 AM12/18/19
to 54bone...@gmail.com, google-adm...@googlegroups.com

Hi Andy,

 

Thank you for attempting the solution I've suggested.

 

Could you kindly post the Logcat error logs that you've encountered after having tried the solution?

 

As for your concern with regard to the issue you're having on the AdMob SDK version 4.10.0: could you confirm if you have an internet connection on your test device? The code might treat the banner ad as having failed the initialization if there was no internet connection during that time.

A Bones

unread,
Dec 18, 2019, 1:48:10 PM12/18/19
to Google Mobile Ads SDK Developers
Logcat is attached.

It is stating it was not initialized, but I have proper entries in androidManifest.xml and on inspector pane for GoogleMobileAds.
logcat (3).txt

A Bones

unread,
Dec 18, 2019, 9:09:46 PM12/18/19
to Google Mobile Ads SDK Developers
Here is an update:

The original error was caused by two plugins 
CPNP v1.5.7 (Cross Platform Native Plugins) which is used to manage my PlayGames connections and leaderboards.
GooglePlayMobile Ads v 3.13.0

Since your suggestion did nto completely work, I went ahead and did many other fix attempts.
I am getting close, the latest solution was as follows:

Clean Rebuild from a known good project without Ads, but CPNP running fine with Play services.
  • CPNP Patch 1.5.8 Android X libraries GoogleAds 4.10.0 Latest Version installed
  • PlayServices Resolver 1.2.135.0 Installed
  • Made proper entries to AndroidManifest.xml and inspector panel for GoogleMobileAds.
  • Forced resolve, androidx libs are present, and enabled for android builds.

Status:
GoogleAds will load banners and rewarded ads with no issues
App no longer crashes on apk or aab installs, Google test devices do not crash.

However, CPNP can detect the GooglePlay services are available,
but will not properly authenticate.
Access to user GooglePlay data and leaderboards/achievements is not working without authentication.

Do you want an updated zip of this project folder?

Mobile Ads SDK Forum Advisor Prod

unread,
Dec 18, 2019, 9:44:20 PM12/18/19
to 54bone...@gmail.com, google-adm...@googlegroups.com

Hi Andy,

 

Glad to hear that you've got most of your setup working.

 

It seems that you've got AdMob SDK working properly on your end, and only the Cross Platform Native Plugins (CPNP) is acting up at this point. Given that this is a third-party plugin, I'm afraid that we will not be able to provide any more insights on it. I would recommend that you contact the support channels for CPNP for further assistance on this.

A Bones

unread,
Dec 19, 2019, 11:03:39 AM12/19/19
to google-adm...@googlegroups.com
Yes, thank you. You may close my ticket. For the sanity of others who might run into this, here are my final notes: Thank you for your help.


Just wanted to make some notes for others as this has been resolve.

On Unity 2017.4.301f running CPNP 15.7 everything worked fine. Added Google Ads 3.13.0 assuming it would work like SUko, but since we are in 2017, the resolver created duplicate class entries and caused build crashes.

The error looked like this:
stderr[
D8
: Program type already present: android.support.v4.os.ResultReceiver$1



FAILURE
: Build failed with an exception.


* What went wrong:
Execution failed for task ':transformDexArchiveWithExternalLibsDexMergerForRelease'.



Online solutions suggested:
  • Resolving as a multidex error - not my issue
  • Duplicate NDK installed on PC - 2 on system, removed NDK in Android Studio, kept NDKR18 but no effect.
  • Use Gradle Experimental, allowed build, but app would crash on all devices.

So none of those were my issue.
When Gradle experimental used, it would build, but APP would instantly crash.

Further attempts resulted in weird behavior, like app build going ok, but app would crash, stating Ad unit ID and size not declared, an error usually for Android Studio. Definitely an issue with cross linked resolver files with the CPNP plugin and GoogleMobile Ads.

We were able to get it to build crash free by using GoogleAds 3.13.0 and 4.10.0 paired with CPNP updates, and but the GPLay service would not authenticate. CPNP support determined that their update for Unity 2017.4. to use AndroidX files had an erroneous Features.GameServices.jar file. We patched that file, and Ads are running, with all GPlay services intact,

Both GoogleMobileAds and CPNP had to be updated to use the latest Androidx resolved files.

A Bones

unread,
Dec 19, 2019, 11:06:34 AM12/19/19
to Google Mobile Ads SDK Developers


On Thursday, December 19, 2019 at 8:03:39 AM UTC-8, A Bones wrote:
Yes, thank you. You may close my ticket. For the sanity of others who might run into this, here are my final notes: Thank you for your help.
Just wanted to make some notes for others as this has been resolve.

On Unity 2017.4.301f running CPNP 15.7 everything worked fine. Added Google Ads 3.13.0 assuming it would work like SUko, but since we are in 2017, the resolver created duplicate class entries and caused build crashes.

The error looked like this:
stderr[
D8
: Program type already present: android.support.v4.os.ResultReceiver$1


FAILURE
: Build failed with an exception.


* What went wrong:
Execution failed for task ':transformDexArchiveWithExternalLibsDexMergerForRelease'.



Online solutions suggested:
  • Resolving as a multidex error - not my issue
  • Duplicate NDK installed on PC - 2 on system, removed NDK in Android Studio, kept NDKR18 but no effect.
  • Use Gradle Experimental, allowed build, but app would crash on all devices.

We also attempted GoogleMobileAds support suggestion of disabling the AndroidX files for android builds in thread above, which allowed the build to succeed, but that disabled GooglePlay services from functioning. 
So none of those were my issue.
Reply all
Reply to author
Forward
0 new messages