AdMob with Unity 5.1.1 (java.lang.NoClassDefFoundError: android.support.v4.util.SimpleArrayMap)

392 views
Skip to first unread message

Dino Velić

unread,
Jan 25, 2016, 6:17:31 PM1/25/16
to Google Mobile Ads SDK Developers
Hi.

I've been trying to implement AdMob in Unity game via the official tutorial (https://developers.google.com/admob/android/games).

The error that I get is:
java.lang.NoClassDefFoundError: android.support.v4.util.SimpleArrayMap

You can find the full log in the attachment.

What I did:
- Downloaded GoogleMobileAdsPlugin
- Put it in Assets/Plugins/Android
- Copied google-play-service-lib to the same folder as above
- Copied AndroidManifest.xml from Unity folder (attached)

The code I used:

 #if UNITY_ANDROID
        string adUnitId = "ca-app-pub-my-id";
        #elif UNITY_IPHONE
            string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
        #else
            string adUnitId = "unexpected_platform";
        #endif

        // Create a 320x50 banner at the top of the screen.
        BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);

        AdRequest request = new AdRequest.Builder()
        .AddTestDevice(AdRequest.TestDeviceSimulator)       // Simulator.
        .AddTestDevice("my device id")
        .Build();

        bannerView.LoadAd(request);


I've also tried exporting Unity project and setting everything up in Eclipse, along with GoogleMobileAdsPlugin and google-play-service-lib, adding support libraries, including them in build path, exporting in build path, adding android-support-v4.jar to projects, but nothing helped.

I would appreciate any ideas.

Thank you
log.txt
AndroidManifest.xml

Veer Arjun Busani

unread,
Jan 26, 2016, 10:21:24 AM1/26/16
to Google Mobile Ads SDK Developers
Hi Dino,

I have gone through your log and the code snippet and I have the following suggestions for you - 
  • Try to make a build from Unity itself and see if it works. Also try to test from a different device or maybe from an emulator. I have attached a sample APK, see if you are able to run it on your device. I have also attached a complete project, but before you build it, make sure that you have the latest libraries.
  • Next would be to add android-support-v4.jar library to Assets -> Plugins -> Android and see if that works for you. Sometimes the SDK would try to load the SimpleArrayMap support class and would crash if it's not found. Try to do this in Unity itself rather than Eclipse.
  • Finally update the Google Play Services library. If you have done so, you need to update a couple of things - 
    • Copy the version.xml file from google-play-services-lib -> res -> values and paste it into Assets -> Plugin -> Android -> GoogleMobileAdsPlugin -> res -> values.
    • Next add this into your GoogleMobileAdsPlugin -> AndroidManifest.xml  file  - 
 <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
Also do let us know the device that you are trying to build on. If it's device specific try to reset the device and see if that works.

Attachments:
Thanks,
Veer Arjun Busani
Mobile Ads SDK Team

Dino Velić

unread,
Jan 31, 2016, 8:45:06 AM1/31/16
to google-adm...@googlegroups.com
Hi Veer,

updating Google Play Services library helped and everything else was really easy to implement.
Also, one of my problems was that I had two Android SDK paths. One for Unity and one old for Eclipse. Big mistake.

Thank you for your help, it's been bugging me for days!

Dino

--

---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/XRTjYwr_0NE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages