[英]Google admob error inflating class com.google.ads.adview with reference from Google Play services library project
I have a project that is using google admob. 我有一个正在使用Google admob的项目。 It had
.jar
file in /libs
, but I want to change it and use google play services. 它在
/libs
有.jar
文件,但我想更改它并使用Google Play服务。 I include it in "Properties>Android>library" from "google-play-services" project. 我将其包含在“ google-play-services”项目的“属性> Android>库”中。 And now i get
error inflating class com.google.ads.adview
. 现在我得到了
error inflating class com.google.ads.adview
。 Can anyone help me why do i get that? 谁能帮我为什么我得到那个? Thank you.
谢谢。
com.google.ads.adview
is the class from the 6.4.1 (and earlier) versions of Admob. com.google.ads.adview
是Admob 6.4.1(或更早版本)版本中的类。
You want to use com.google.android.gms.ads.AdView
See https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals 您想使用
com.google.android.gms.ads.AdView
参见https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals
You need to change the api. 您需要更改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"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.