升级到新的Admob问题

Joh*_*red 2 android admob

首先,我把它放到我的清单中

<activity android:name="com.google.android.gms.ads.AdActivity" 
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

<meta-data android:name="com.google.android.gms.version" 
    android:value="@integer/google_play_services_version"/>
Run Code Online (Sandbox Code Playgroud)

然后,每个布局我希望广告出现在里面,我在它把这个.xml

          xmlns:ads="http://schemas.android.com/apk/res-auto"
Run Code Online (Sandbox Code Playgroud)

而这个下来

<com.google.android.gms.ads.AdView 
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adUnitId="ca-abb-psb-4557896546544844/5789887777"
    ads:adSize="BANNER"
    ads:loadAdOnCreate="true" 
    android:layout_gravity="center"
    android:layout_margin="10dp">
</com.google.android.gms.ads.AdView>    
Run Code Online (Sandbox Code Playgroud)

最后,我导入了这个库 google-play-services_libs

现在问题是我error: No resource identifier found for attribute 'loadAdOnCreate' in package 'aaa.bbb.ccc'<com.google.android.gms.ads.AdView .... >xml中得到的.

我进入R cannot be resolved to a variable了所有的应用课程.

Ale*_*Bcn 9

查看https://developers.google.com/android/reference/com/google/android/gms/ads/AdView#xml-attributes

LoadOnCreate 不能再用作XML属性.

<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"/>
Run Code Online (Sandbox Code Playgroud)
// 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);
Run Code Online (Sandbox Code Playgroud)