在我的应用程序中集成 Admob

Integrating Admob in my application

我是新手 android.currently 我正在使用 Eclipse 和 android 4.0 api 14.Before 集成 admob 一切正常 well.after 集成 admob 显示错误 "no resource identifier found for attribute adsize" 和 "no resource identifier found for attribute adUnitId" 在 main.xml

我发现了很多类似的问题,但无法解决。

我的 main.xml 文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
        android:id="@+id/adLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:orientation="vertical" >
    <com.google.android.gms.ads.AdView 
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="@string/admob_publisher_id"/>
        </LinearLayout>
        </RelativeLayout>

主要activity.java

    import com.google.android.gms.ads.*;

    AdView adView = (AdView)this.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);

清单文件

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.easywebapp"
android:installLocation="auto"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


<application
    android:allowBackup="true"
    android:hardwareAccelerated="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
    <meta-data android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
    <activity
        android:name="com.example.asd.Splashscreen"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.example.asd.Image"
        android:label="@string/title_activity_image" >
    </activity>
    <activity android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />
</application>

试试下面的方法 link refer here

<com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_home_footer">
    </com.google.android.gms.ads.AdView>

将此添加到您的 gradle 文件中

compile 'com.google.android.gms:play-services-ads:10.2.0'

代码似乎是 fine.Check google 如果包含播放服务库,请验证其路径。