18

I am attempting to incorporate admob ads in my app. So far I have added the following code in the onCreate method of my app's main activity...

    adView = new AdView(this,AdSize.BANNER,"my code number");
    adView.loadAd(new AdRequest());

The program compiles without error but at run time I get the message java.lang.NoClassDefFoundError: com.google.ads.AdView. I have seen a supposed explanation of the problem and the cure here but I could not see how it was applicable to my project because I do not have either a "lib" or "libs" directory within my project.

According to eclipse's SDK manager, I have the most up to date version of everything that I use.

Mick
  • 8,284
  • 22
  • 81
  • 173
  • The idea is if you reference a third party library and it's not provided by your reference platform, you need to make sure this library is deployed together with your application and is located on your application classpath in the end. – maksimov Apr 27 '12 at 15:31
  • 2
    see this answer http://stackoverflow.com/a/10046725/1289716 – MAC Apr 27 '12 at 15:32
  • @gtumca-MAC: yes, that'd done the trick. If you put it as an answer I will give it a tick. – Mick Apr 27 '12 at 15:38
  • see the link that ans was posted by me you can give vote over there – MAC Apr 27 '12 at 17:10

10 Answers10

33

I had a similar problem, but did not have to add the libs folder; I tried, with no success, then removed them afterwards, when I realized that I had just forgotten to export the included Jar archived.

Fix:
Select project settings > Java Build Path, then Order and export.

Here, check the GoogleAdMobAdsSdk-package.

This should solve the NoClassDefFoundError-issue.

Kjartan
  • 18,591
  • 15
  • 71
  • 96
23

Just create manually the "libs" folder, and add your libraries there. By default, they doesn't exist

Yotes
  • 378
  • 3
  • 16
13
  1. Project-> Clean
  2. Project settings -> Java Build Path. Open "Order and export" tab.
  3. Check GoogleAdMobsAdsSDK.

It is worked for me.

N3CAT1
  • 367
  • 4
  • 13
6

Was getting this error updating from android 16 to 20.

Solved by going to Java Build Path, Order and Export tab, checked and moved GoogleAdMobAdsSdk just under my source. For some reason that fixed it.

Changing the order back didn't break it. So some setting must have needed to be initialized.

Tim Johnson
  • 61
  • 1
  • 1
1

I had this problem, and this problem too:

Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode and Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode

Despite many hours of following all solutions listed the only way I could get my app to work was to use the AdMob banner example here:

https://github.com/googleads/googleads-mobile-ios-examples/tree/master/admob/SmartBannerExample

And re-build my project around it, copying my files in to that project. If you are stuck, try it.

Don't know why it worked, but now it does. Something in my project was very wrong. Now I can carry on with my work. I love Google/Android, but really what a mess!

Community
  • 1
  • 1
0

See this answer Android update 17 seems incompatible with external Jars.

You need to put all jars in libs folder insted of lib.

Community
  • 1
  • 1
MAC
  • 15,799
  • 8
  • 54
  • 95
0

It's not enough only to add "GoogleAdMobAdsSdk-6.4.1.jar" in Java Build Path,then you should switch to table:Order and export.check the "GoogleAdMobAdsSdk-6.4.1.jar" here.

rigortek
  • 25
  • 5
0

UPDATE:

Select project settings > Java Build Path, then Order and export.

Here, check the google-play-services.jar.

This should solve the NoClassDefFoundError-issue.

juan Isaza
  • 3,646
  • 3
  • 31
  • 37
0

In my case I needed to click on the "Android Private Libraries" on the "Order and Export" Tab

Eli
  • 707
  • 8
  • 16
0

Go to Properties - Java Build Path - Order and Export and check every Checkmark! That did the trick for my project.

Chris
  • 4,403
  • 4
  • 42
  • 54