【问题标题】:Can't get Admob to work无法让 Admob 工作
【发布时间】:2015-12-18 17:09:46
【问题描述】:
 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。从谷歌开发网站添加了上述代码。在应用的项目结构中,我还启用了 Admob。

编辑

我现在知道问题出在哪里,但无法解决。我已经从项目结构中启用了 Admob,它已经添加了

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

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

在我的应用中,play-services 仅显示在 build.gradle 中,而不显示在外部库中。我只在我的 External Libraries 列中看到 Android API 23 Platform、、android-android-23 和 support-annotations。我尝试清理项目,重建并尝试使缓存/重新启动无效。他们都没有工作。有什么建议吗?

【问题讨论】:

  • 您是否将其添加到布局的根元素“xmlns:ads="schemas.android.com/apk/res-auto"?
  • 是的,我已经添加了 -> xmlns:ads="schemas.android.com/apk/res-auto"
  • 再次重建您的项目。
  • 你在使用 Android Studio 吗?
  • 又是同样的问题..顺便说一句,我认为我没有添加罐子。如何添加?

标签: java android admob


【解决方案1】:

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

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

编辑

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

【讨论】:

  • 我编辑了我的答案下载示例项目并对其进行测试以查看问题是否在您的代码中或来自 android studio 或 SDK。
  • 我也看过一个横幅示例项目。它有效,但我的项目没有。
  • 您是否将依赖项添加到应用级 build.gradle 或项目级文件?
  • App 级 build.gradle 添加依赖项
  • 您能否发布与问题相关的 MainActivity 代码,以便我们调查问题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-23
相关资源
最近更新 更多