首页 文章

无法让Admob工作

提问于
浏览
0
import com.google.android.gms.ads.AdRequest;
 import com.google.android.gms.ads.AdView;

它表示无法解析符号AdRequest并且无法解析Adview . 我究竟做错了什么?在我的主要活动文件中包含以下内容

<com.google.android.gms.ads.AdView
        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/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView><com.google.android.gms.ads.AdView
        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/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView>

另外,我已将以下内容添加到Build.gradle中

dependencies {


compile 'com.android.support:support-v4:23.1.1'
compile 'com.google.android.gms:play-services-ads:8.3.0'
}

我想在我的应用上显示 Banner 广告,我第一次使用Admob . 从谷歌开发网站添加了上述代码 . 在应用程序的项目结构中,我还启用了Admob .

EDIT

我现在知道问题是什么,但无法修复 . 我已经从项目结构启用了Admob,它已经添加了

compile 'com.google.android.gms:play-services:8.4.0'

在build.gradle中 . 我查了一个 Banner 示例,示例在外部库中有播放服务,但它没有出现在我的应用程序中 .

在我的应用程序中,播放服务仅显示在build.gradle中,但不显示在外部库中 . 我只在外部库列中看到Android API 23平台,<1.8>,android-android-23和support-annotations . 我尝试清理项目,重建并尝试Invalidate cache / Restart . 他们都没有工作 . 有什么建议?

1 回答

  • 0

    我在上一个项目中遇到了同样的问题,我就这样解决了

    转到 Build 菜单

    点击 Clean Project

    让它再次完成 Build 菜单并点击 Rebuild Project

    如果这没有解决它 .

    试试这个

    您需要编辑清单文件

    application 标签后发布此广告

    <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    
    
        <!-- Include the AdActivity configChanges and theme. -->
        <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent" />
    

    EDIT

    下载谷歌在他们的教程here中提供的this example,看看它是否有效,让我们知道结果是什么

相关问题