Android Studio AdMob

I’ve switched over from Eclipse to use Android Studio and have everything working, except when trying to incorporate AdMob into my project. I had the code set up correctly from my previous project, so it’s a matter of telling Android Studio to build with it.

I’ve been reading a lot of questions about adding the .jar into the libs folder, except I think the newest version of Android Studio changed the layout. So I just dragged it into .idea > libraries and then Right-Clicked and ‘Add As Library’.

Within Project Structure, I have two modules, and -. Under -, it shows all the dependencies listed which includes support-v4-18.0.0 and GoogleAdMobAdsSdk-6.4.1, marked as Export and Compile for Scope.

Within the Preview window in Android Studio, it shows the AdView correctly, but when running it it crashes. I’ve tried using ‘gradlew clean’ and rebuilding the project numerous times without success.

Currently, the project works correctly unless I have the AdView on any layout. If I do have it on a page, I get “java.lang.ClassNotFoundException: com.google.ads.AdView” pointing to the line where I use an inflater to inflate my layout.

Callstack:

    android.view.InflateException: Binary XML file line #155: Error inflating class com.google.ads.AdView
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
        at com.awestruck.pokedex.Display_Main.onCreateView(Display_Main.java:53)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
        at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
        at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
        at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
        at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
        at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
        at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
        at android.view.View.measure(View.java:15279)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4832)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
        at android.view.View.measure(View.java:15279)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4832)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at android.view.View.measure(View.java:15279)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
        at android.view.View.measure(View.java:15279)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4832)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2271)
        at android.view.View.measure(View.java:15279)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2091)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1253)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1483)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1151)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4661)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
        at android.view.Choreographer.doCallbacks(Choreographer.java:555)
        at android.view.Choreographer.doFrame(Choreographer.java:525)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
        at android.os.Handler.handleCallback(Handler.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:155)
        at android.app.ActivityThread.main(ActivityThread.java:5493)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
        at android.view.LayoutInflater.createView(LayoutInflater.java:552)

Which points to the line:

        v = inflater.inflate(R.layout.display_main, container, false);

build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}

apply plugin: 'android'



repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.0"

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 18
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:18.0.0'
    compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar')
}

Thanks for any help.

Admob android studio, crashing app

I have put the admob .jar file in my project via project structure: And I added code in for the admob banner into my layout files: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:

Unable to Add AdMob SDK to Android Project in Android Studio

I’m trying to use the latest version of the Admob SDK that is built into Google Play Services in my project using Android Studio but it is not recognizing activity android:name=com.google.android.gm

Android Studio AdMob Integration With Google Play Services

I am trying to add admob features to my application. I have done everything but I am missing some key points. Here is my graddle: apply plugin: ‘android’ android { compileSdkVersion 19 buildToolsVers

Android admob cant see

Admob code cant see on device. i followed the instructions here: http://www.admob.com/docs/AdMob_Android_SDK_Instructions.pdf everything ok, but the 6. not clear for me Step 6 When integrating AdM

Android admob permissions

my android app already has the following permission: android.permission.INTERNET I want to use the admob ads in ma application. I have seen a lot of examples how to use the admob in android and alway

Admob for Android Canvas

I have a project on going and I am suppose to place Admob ads on canvas in android. Is it possible to place Admob ads on Canvas in Android.

Android AdMob example

I downloaded example code of an Android project featuring AdMob ads from here. In the picture, the ad says AdMob Test Android Web Ad, but when I run the code, I sometimes see an actual ad and someti

Trying to set up admob in Android Studio

I have been following this tutorial here: Android Studio – Importing external Library/Jar I downloaded the jar and placed it in my lib folder for my project. I then added this line to my build.gradle:

Android – Admob SurfaceView

I am new to android development, but I am trying to add admob to my app which is using a surfaceview (panelView – GameView). I tried following http://rx-games.com/admob-adverts-on-surfaceview-no-xml-t

AdMob intregation in Android

I am implementing AdMob in my app. I have added xml codes. <LinearLayout android:layout_width=match_parent android:layout_height=match_parent android:orientation=vertical > <com.google.

Answers

Problem solved, after awhile, I managed to get it.

For anyone looking to figure out this issue, create a new libs folder and put the GoogleAdMobAdsSdk-6.4.1.jar within it. And make sure your dependencies is:

dependencies {
    compile 'com.android.support:appcompat-v7:18.0.0'
    compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar')
}

Although, I’m unsure exactly where the folder needs to go, I just copy-pasted the same folder everyone and then ran:

gradlew clean

Then hopefully that should work.