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(我甚至无法导入它,因为它没有出现)
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管理器并安装它。”但我已经安装了谷歌存储库,它是最新版本
# 1 楼答案
看看这是否有帮助:在
Android Studio
中执行以下操作-转到文件>项目结构
在打开窗口的左侧,在开发者服务下,选择广告
选中AdMod旁边的复选框。你的窗户应该是这样的:
单击确定
这将向Android的
build.gradle
添加所需的依赖项,并同步Gradle同步完成后,为了确保清洁和重建项目:
更新: 实际上,我认为这是在
android
项目的build.gradle
文件中添加“广告依赖项”。因此,如果上述教程不起作用,请尝试添加到
android
项目中build.gradle
文件的底部(不是core
项目下的那个)我希望这有帮助
# 2 楼答案
试试这个:
另外,请确保已从Android SDK管理器下载并更新到您正在使用的版本