有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java我无法为安卓导入或使用AdView

我正在用libgdx制作一个安卓游戏,我想添加广告横幅,所以我在网上遵循了一些说明

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

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

更新 我的项目结构不同 my project structure doesn't have ads

project(":安卓") {
    apply plugin: "安卓"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-安卓:$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.安卓.gms:play-services-ads:8.4.0"
    }
}

当我在底部突出显示编译google play services-ads的代码时,它会显示这样一条消息“依赖于play services,但SDK安装没有“Extras>;Google Repository“已安装。打开SDK管理器并安装它。”但我已经安装了谷歌存储库,它是最新版本


共 (2) 个答案

  1. # 1 楼答案

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

    1. 转到文件>项目结构

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

    3. 选中AdMod旁边的复选框。你的窗户应该是这样的: enter image description here

    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项目下的那个)

    我希望这有帮助

  2. # 2 楼答案

    试试这个:

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

    另外,请确保已从Android SDK管理器下载并更新到您正在使用的版本