Reputation: 1573
I have a project that is using google admob. It had .jar
file in /libs
, but I want to change it and use google play services. I include it in "Properties>Android>library" from "google-play-services" project. And now i get error inflating class com.google.ads.adview
.
Can anyone help me why do i get that?
Thank you.
Upvotes: 1
Views: 651
Reputation: 7927
You need to change the api. You can follow the official migration guide
Basically, you need to make the changes below:
Change:
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"/>
To:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"/>
// Java code required.
// testDevices and loadAdOnCreate attributes are
// no longer available.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("TEST_DEVICE_ID")
.build();
adView.loadAd(adRequest);
Change:
<activity android:name="com.google.ads.AdActivity"/>
To:
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>`
Add:
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
Don't forget the permissions:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
Upvotes: 1
Reputation: 20196
com.google.ads.adview
is the class from the 6.4.1 (and earlier) versions of Admob.
You want to use com.google.android.gms.ads.AdView
See https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals
Upvotes: 1