Android Studio - Error inflating class com.google.ads.AdView

久未见 提交于 2019-12-04 18:49:18

it's a bit tricky but here is the solution:

The current preview release doesn't edit the build.gradle file, even if you have added the admob library to the dependencies in the menu. What you can do is to add the dependency manually, it's very easy:

double click on the file "build.gradle" on the left in the navigation menu. Add the following line:

compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar')

It should look like:

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

    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
    compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }
}

Right click your project and go to Properties -> Java Build Path. In Libraries add the AdMob SDK jar, and in Order and Export check the AdMob SDK library. Then clean and re-run your application.

Previously, putting 3rd party libraries in the libs/ folder was sufficient for the Android build to bundle these libraries when compiling your app. But since the release of v22 of the Android tools, you now have to explicitly add the library to your build path and export it.

I was the same and achieve fix, I have done just the same as you and I miss you just do the following:

open a terminal (windows or linux) and go to the root of your project, eg AndroidStudioProjects / MyProject

Run the command:

Linux(is the file gradlew): ./gradlew clean

Windows(is the file gradlew.bat): gradlew clean

Now goto: Build > Rebuild Project

That's it, enjoy!!!

Sorry for the bad English

I got same problem.I changed Android.jar to 4.2.2. Now it works fine in both emulator and phone

This may help you integrate admob with your application but google is not going to accept any updated or new apps which use this type of admob integration following 1 August 2014.

https://developers.google.com/mobile-ads-sdk/download#downloadandroid

Instead I recommend you to use Google Play Services version as suggested in above document.

You are most likely using a AdView layout with package name com.google.ads.AdView. Change it to:

 <com.google.android.gms.ads.AdView
        xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/ad"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"

        />

I am also using Android Studio, with build.gradle dependency set like this:

dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.3.23'
}

Moving forward,we are not required to manually add libs that already have Maven coordinates to point to, so do NOT do this.

dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar')
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!