Question

I am writing a code to display Admob Banner in my Android Application. i have done the following few adjustments in order to achieve this:

  • configured google play services library following: https://developers.google.com/mobile-ads-sdk/docs/
  • Added

        <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" /> 
    

and

       <meta-data
       android:name="com.google.android.gms.version"
        android:value="4323000" /> 

code in my manifest file, and also added following permissions:

       <uses-permission android:name="android.permission.INTERNET" />
       <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

the problem occurs when i try to run the application it throws the following exception:

     05-07 14:51:17.617: E/AndroidRuntime(7877): FATAL EXCEPTION: main
     05-07 14:51:17.617: E/AndroidRuntime(7877): java.lang.NoClassDefFoundError:       com.google.android.gms.ads.AdView
     05-07 14:51:17.617: E/AndroidRuntime(7877):    at com.atc.hums.HumsActivity.onCreate(HumsActivity.java:458)
     05-07 14:51:17.617: E/AndroidRuntime(7877):    at android.app.Activity.performCreate(Activity.java:5165)
     05-07 14:51:17.617: E/AndroidRuntime(7877):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1103)
     05-07 14:51:17.617: E/AndroidRuntime(7877):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2419)
     05-07 14:51:17.617: E/AndroidRuntime(7877):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520)
     05-07 14:51:17.617: E/AndroidRuntime(7877):    at android.app.ActivityThread.access$600(ActivityThread.java:162)
     05-07 14:51:17.617: E/AndroidRuntime(7877):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1366)
     05-07 14:51:17.617: E/AndroidRuntime(7877):    at android.os.Handler.dispatchMessage(Handler.java:99)
     05-07 14:51:17.617: E/AndroidRuntime(7877):    at android.os.Looper.loop(Looper.java:158)
     05-07 14:51:17.617: E/AndroidRuntime(7877):    at android.app.ActivityThread.main(ActivityThread.java:5751)
     05-07 14:51:17.617: E/AndroidRuntime(7877):    at java.lang.reflect.Method.invokeNative(Native Method)
     05-07 14:51:17.617: E/AndroidRuntime(7877):    at java.lang.reflect.Method.invoke(Method.java:511)
     05-07 14:51:17.617: E/AndroidRuntime(7877):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
     05-07 14:51:17.617: E/AndroidRuntime(7877):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
     05-07 14:51:17.617: E/AndroidRuntime(7877):    at dalvik.system.NativeStart.main(Native Method)

Was it helpful?

Solution

Adding Google Play Services support to your project

As per the Google Play Services setup guide, one does not simply "add the jars". Since GPS comes bundled with resources, you have to import it as a new seperate project, and reference it from your own, exisiting project.

Please follow the setup guide. I've just verified that I can reference AdView successfully from my own project incorporating GPS.

Ensuring your device supports Google Play Services

GPS is an external service - it's an APK managed by the Play Store app and you need to ensure that the user has the latest GPS APK and/or one that complies with what you wanna do. Here is the guide: Ensure Devices Have the Google Play services APK.

If the device does not have GPS installed (not a Google device, special ROM, AOSP ROM, old Android, etc...) you can not use AdView.

OTHER TIPS

I think you should follow these steps

First step : You should login into admob account and add an app there without url.Click on manage app take ,adunitId from there in the xml layout please place following code.

 <com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="youradunitid"
                     ads:adSize="BANNER"
                     ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                     ads:loadAdOnCreate="true"/>

Second step:In main activity ,please do not again add adview ,because you have already add adview in xml do not forget to put loadAdOnCreate = true

Third step:

You already add essential to manifest.

Fourth step :when you run on emulator it gives test ads

Fifth step :Now you are ready to launch on device

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top