繁体   English   中英

无法使Admob正常工作

[英]Can't get Admob to work

 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'
}

我想在我的应用上显示横幅广告,并且我是第一次使用Admob。 从Google开发者网站添加了以上代码。 在应用程序的项目结构中,我还启用了Admob。

编辑

我现在知道有什么问题,但无法解决。 我已经从Project Structure启用了Admob,它已经添加了

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

在build.gradle中。 我已经检查了一个横幅示例,Example在外部库中具有播放服务,但未在我的应用中显示。

在我的应用中,播放服务仅显示在build.gradle中,而不显示在外部库中。 我在“外部库”列中仅看到Android API 23 Platform,<1.8>,android-android-23和support-annotations。 我尝试清理项目,重建,还尝试了使缓存无效/重新启动。 他们都没有工作。 有什么建议么?

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

转到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" />

编辑

下载这个例子由谷歌提供在他们的教程这里 ,看看是否可行与否,让我们知道结果是什么

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM