找不到com.google.android.gms.ads.AdView

时间:2015-04-05 15:02:06

标签: java android eclipse admob

我已经为此尝试了所有可能的解决方案,但没有任何效果。我一直收到这条消息:

enter image description here

尝试设置广告时!

我更新了我的sdk,更新了所有工具,导入并引用了google-play-services-lib,将其添加到活动下的清单中:

 <activity
        android:name=".MainActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
       <meta-data android:name="com.google.android.gms.version"
       android:value="@integer/google_play_services_version"/>

这是我的xml:

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="xx"
ads:loadAdOnCreate="true"
android:layout_centerHorizontal="true"/>

另外最重要的是:

     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

你可以看到它被引用:
enter image description here
什么都行不通,我做错了什么?

编辑: 整个清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="sp.game.spiceinspace"
    android:versionCode="6"
    android:versionName="BETA 4" >

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/newicon"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@style/AppTheme" >
           <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" />

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Options"
            android:label="@string/title_activity_options" >
        </activity>

        <meta-data
            android:name="io.fabric.ApiKey"
            android:value="436bebecd07f078922828f9273618cb7a7246a3" />
        <activity
            android:name=".GameActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:label="@string/title_activity_game" >
        </activity>
        <activity
            android:name=".MagicAppRestart"
            android:label="@string/title_activity_magic_app_restart" >
        </activity>
    </application>

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

</manifest>

2 个答案:

答案 0 :(得分:1)

更改:

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

为:

xmlns:ads="http://schemas.android.com/apk/res-auto"

答案 1 :(得分:-1)

对我有用的是在代码中创建它:

AdView mAdView = new AdView(this);
        mAdView.setAdSize(AdSize.BANNER);
        mAdView.setAdUnitId("ca-app-pub-1147729513575655/6913222649");
        AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build();
        if(mAdView.getAdSize() != null || mAdView.getAdUnitId() != null)
        mAdView.loadAd(adRequest); 
       // else Log state of adsize/adunit
    ((RelativeLayout)findViewById(R.id.adView)).addView(mAdView );