问题
I am trying to add AdMob ads in my application.
In the manifest I have:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
In the xml activity's layout I use:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/id">
</com.google.android.gms.ads.AdView>
My java code in the main activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAdView = (AdView) findViewById(R.id.adView);
adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
Unfortunately this doesn't work and I receive this error
error: No resource identifier found for attribute 'adSize' in package
回答1:
Other people who has faced this issue had solution by replacing /res
with /lib
in custom layout nampespace.
xmlns:android="http://schemas.android.com/apk/res/android" will be
xmlns:yourApp="http://schemas.android.com/apk/lib/com.yourApppackage.yourClass"
来源:https://stackoverflow.com/questions/29994738/no-resource-identifier-found-for-attribute-adsize-in-package