【问题标题】:I can't import or use AdView for android我无法导入或使用 AdView for android
【发布时间】:2016-01-23 12:45:33
【问题描述】:

我正在使用 libgdx 制作一个安卓游戏,我想添加广告横幅,所以我按照网上的一些说明进行操作。

// I added this code on build.gradle in the dependencies:
compile "com.google.android.gms:play-services-ads:8.3.0"

然后将最小 sdk 设置为 9,它没有要求我同步,所以我手动完成(顺便说一下,我使用的是 intellij)然后当我尝试在 AndroidLauncher 上添加代码时,我无法使用 AdView(我甚至无法导入它,因为它没有出现)。

更新 我的项目结构不同

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
        compile "com.google.android.gms:play-services-ads:8.4.0"
    }
}

当我突出显示用于编译 google play 服务的代码时 - 底部的广告会显示此消息“依赖于 Play 服务,但 SDK 安装没有安装“Extras > Google Repository”。打开 SDK 管理器并安装它。”但我安装了 google 存储库,它是最新版本。

【问题讨论】:

  • 显示完整的依赖块

标签: java android libgdx admob


【解决方案1】:

看看这是否有帮助:在Android Studio 中执行以下操作-

  1. 转到文件 --> 项目结构

  2. 在打开的窗口左侧的开发者服务下,选择广告

  3. 选中 AdMod 旁边的复选框。您的窗口应如下所示:

  4. 点击确定

这会将所需的依赖项添加到 Android 的 build.gradle,并同步 Gradle。

同步完成后,确保清理并重建您的项目:

  1. 构建 --> 清理项目
  2. 构建 --> 重建项目

更新: 实际上,我认为这样做是将“广告依赖项”添加到android 项目中的build.gradle 文件中。所以如果上面的教程不起作用,请尝试添加

dependencies {
    compile 'com.google.android.gms:play-services-ads:8.4.0'
}

android 项目中build.gradle 文件的底部(不是core 项目下的那个)。

我希望这会有所帮助。

【讨论】:

  • @StormAsdg 我更新的答案能解决你的问题吗?
  • 所以我在android下的build.gradle上添加了上面的代码,但仍然是同样的问题。
  • @StormAsdg 你清理和重建项目了吗?如果这没有帮助,请尝试重新启动您的 IDE。
  • 我做了所有这些,我唯一可以导入的是“com.google.android.gms.ads.R;”
【解决方案2】:

试试这个:

  1. 移除依赖和admob代码
  2. 执行文件 -> 使缓存无效并重新启动
  3. 重新添加依赖项。
  4. 与 gradle 同步

还要确保从 Android SDK 管理器下载组件并更新到您正在使用的版本。

【讨论】:

  • 我这样做了,但什么也没发生,你如何与 gradle 同步?我所做的是删除所有依赖代码,包括 android 上的 admob 代码
【解决方案3】:

我通过将我的 intellij ide 从版本 14 更新到 15 解决了这个问题,它基本上重新安装了 ide,我不得不再次导入整个项目。

【讨论】:

    猜你喜欢
    • 2022-11-02
    • 2019-06-16
    • 2018-04-29
    • 2022-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-08
    • 1970-01-01
    相关资源
    最近更新 更多