I have two different dev computers, a PC and a Mac Laptop. I frequently work on one, check into a private repo on BitBucket, and switch to another.
Recently I have been trying to add Ads to an Android application (my first) using adMob. I kept getting the "Error inflating class com.google.adroid.gms.ads.AdView" printed out in my LogCat when I try to run the app in the emulator.
I tried all the usual things found Googling:
- Made sure that I imported a copy of the google-play-services-lib into my workspace.
- Made sure my project referenced said library, and that the referenced library had a green tick next to it.
- Made sure I had updated AndroidManifest.xml with required permissions, meta-data, and activity.
- Made sure my activity .xml file is importing the the correct xmlns: xmlns:ads="http://schemas.android.com/apk/res-auto"
Finally I imported the GoogleAdsSampleActivity example into my workspace, added the google-play-services_lib as a library, and added my ad_unit_id, and it still wouldn't work.
On a whim, I checked everything in, and switched to my Mac. Everything works fine. Going back to my PC, I can get it to run in Android Studio, just not in eclipse, my Mac and PC are both using the same version of Eclipse (4.4.1 Build Id: 20140925-1800) and ADT (23.0.4.1468518). I have tried re-installing eclipse, re-installing ADT, using an older version of Eclipse, and even turning it off and on again, but I keep getting the same error.
Has anyone seen this before? Any other suggestions on what else I can try?
Thanks
Update As requested, here is the full stack trace:
01-19 14:28:26.130: E/AndroidRuntime(1067): FATAL EXCEPTION: main
01-19 14:28:26.130: E/AndroidRuntime(1067): Process: com.google.android.gms.samples.ads, PID: 1067
01-19 14:28:26.130: E/AndroidRuntime(1067): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.gms.samples.ads/com.google.android.gms.samples.ads.BannerXmlActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class com.google.android.gms.ads.AdView
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.app.ActivityThread.access$800(ActivityThread.java:135)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.os.Handler.dispatchMessage(Handler.java:102)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.os.Looper.loop(Looper.java:136)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.app.ActivityThread.main(ActivityThread.java:5017)
01-19 14:28:26.130: E/AndroidRuntime(1067): at java.lang.reflect.Method.invokeNative(Native Method)
01-19 14:28:26.130: E/AndroidRuntime(1067): at java.lang.reflect.Method.invoke(Method.java:515)
01-19 14:28:26.130: E/AndroidRuntime(1067): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
01-19 14:28:26.130: E/AndroidRuntime(1067): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
01-19 14:28:26.130: E/AndroidRuntime(1067): at dalvik.system.NativeStart.main(Native Method)
01-19 14:28:26.130: E/AndroidRuntime(1067): Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class com.google.android.gms.ads.AdView
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
01-19 14:28:26.130: E/AndroidRuntime(1067): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.app.Activity.setContentView(Activity.java:1929)
01-19 14:28:26.130: E/AndroidRuntime(1067): at com.google.android.gms.samples.ads.BannerXmlActivity.onCreate(BannerXmlActivity.java:34)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.app.Activity.performCreate(Activity.java:5231)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
01-19 14:28:26.130: E/AndroidRuntime(1067): ... 11 more
01-19 14:28:26.130: E/AndroidRuntime(1067): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.AdView" on path: DexPathList[[zip file "/data/app/com.google.android.gms.samples.ads-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.google.android.gms.samples.ads-1, /system/lib]]
01-19 14:28:26.130: E/AndroidRuntime(1067): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
01-19 14:28:26.130: E/AndroidRuntime(1067): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
01-19 14:28:26.130: E/AndroidRuntime(1067): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.view.LayoutInflater.createView(LayoutInflater.java:559)
01-19 14:28:26.130: E/AndroidRuntime(1067): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
01-19 14:28:26.130: E/AndroidRuntime(1067): ... 21 more
Additionally, I realized that my emulator was running Android API level 17, so I thought this was the problem. Strangely enough, even though all the system images were installed, it would not let me create an emulator that would run level 19. Upon further investigation, I found that Eclipse was pointing to a version of the SDK that I installed manually, presumably a couple (or few) years ago. I changed it to use the same SDK that Android Studio is using and can now create a level 19 emulator, but am still getting this same error.
Concerning the code, I have made no changes to the GoogleAdsSampleActivity sample other than adding my own ad_unit_id. That is the sample I ran to get the above error.