我正在为android构建一个应用程序,并使用libGdx,我检查了一百万个有关如何添加Admob的教程,每个教程都要求调整build.gradle文件,但我的文件与他们的文件不一样,它们之间存在依赖关系和不同的内容,任何想法如何在我的build.gradle上添加admob?
android build.gradle:
android {
buildToolsVersion "25.0.2"
compileSdkVersion 25
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
instrumentTest.setRoot('tests')
}
packagingOptions {
exclude 'META-INF/robovm/ios/robovm.xml'
}
defaultConfig {
applicationId "com.badlogic.drop"
minSdkVersion 8
targetSdkVersion 25
}
}
// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() {
file("libs/armeabi/").mkdirs();
file("libs/armeabi-v7a/").mkdirs();
file("libs/arm64-v8a/").mkdirs();
file("libs/x86_64/").mkdirs();
file("libs/x86/").mkdirs();
configurations.natives.files.each { jar ->
def outputDir = null
if(jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
if(outputDir != null) {
copy {
from zipTree(jar)
into outputDir
include "*.so"
}
}
}
}
task run(type: Exec) {
def path
def localProperties = project.file("../local.properties")
if (localProperties.exists()) {
Properties properties = new Properties()
localProperties.withInputStream { instr ->
properties.load(instr)
}
def sdkDir = properties.getProperty('sdk.dir')
if (sdkDir) {
path = sdkDir
} else {
path = "$System.env.ANDROID_HOME"
}
} else {
path = "$System.env.ANDROID_HOME"
}
def adb = path + "/platform-tools/adb"
commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.badlogic.drop/com.badlogic.drop.AndroidLauncher'
}
// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
// need to specify Java source sets explicitly, SpringSource Gradle Eclipse plugin
// ignores any nodes added in classpath.file.withXml
sourceSets {
main {
java.srcDirs "src", 'gen'
}
}
jdt {
sourceCompatibility = 1.6
targetCompatibility = 1.6
}
classpath {
plusConfigurations += [ project.configurations.compile ]
containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
}
project {
name = appName + "-android"
natures 'com.android.ide.eclipse.adt.AndroidNature'
buildCommands.clear();
buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
buildCommand "org.eclipse.jdt.core.javabuilder"
buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
}
}
// sets up the Android Idea project, using the old Ant based build.
idea {
module {
sourceDirs += file("src");
scopes = [ COMPILE: [plus:[project.configurations.compile]]]
iml {
withXml {
def node = it.asNode()
def builder = NodeBuilder.newInstance();
builder.current = node;
builder.component(name: "FacetManager") {
facet(type: "android", name: "Android") {
configuration {
option(name: "UPDATE_PROPERTY_FILES", value:"true")
}
}
}
}
}
}
}
和核心build.gradle:
apply plugin: "java"
sourceCompatibility = 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = [ "src/" ]
eclipse.project {
name = appName + "-core"
}
最后是桌面build.gradle:
apply plugin: "java"
sourceCompatibility = 1.6
sourceSets.main.java.srcDirs = [ "src/" ]
project.ext.mainClassName = "com.badlogic.drop.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../android/assets");
task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
}
task dist(type: Jar) {
from files(sourceSets.main.output.classesDir)
from files(sourceSets.main.output.resourcesDir)
from {configurations.compile.collect {zipTree(it)}}
from files(project.assetsDir);
manifest {
attributes 'Main-Class': project.mainClassName
}
}
dist.dependsOn classes
eclipse {
project {
name = appName + "-desktop"
linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/android/assets'
}
}
task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
doLast {
def classpath = new XmlParser().parse(file(".classpath"))
new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
def writer = new FileWriter(file(".classpath"))
def printer = new XmlNodePrinter(new PrintWriter(writer))
printer.setPreserveWhitespace(true)
printer.print(classpath)
}
}
忘记桌面和核心模块的build.gradle。
希望您使用的是Firebase Admob集成,而不是旧版AdMob集成,因此请先集成Firebase,然后再集成Admob Ad。
将这部分添加到android模块的build.gradle中。
dependencies {
compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.firebase:firebase-ads:10.2.1'
compile 'com.android.support:support-annotations:25.3.1'
}
apply plugin: 'com.google.gms.google-services'
在根项目的build.gradle文件中
在buildscript中添加为依赖项以进行Firebase集成。
classpath 'com.google.gms:google-services:3.0.0'
AndroidManifest.xml中的更改
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
开始编码部分,初始化MobileAds后创建视图。
MobileAds.initialize(activity.getApplicationContext(), APP_ID);
initView();
protected void initView(){
// Create and setup the AdMobHelper view
topView = new AdView(activity);
topView.setAdSize(AdSize.BANNER);
topView.setAdUnitId(TopAdUnitId);
bottomView = new AdView(activity);
bottomView.setAdSize(AdSize.BANNER);
bottomView.setAdUnitId(BottomAdUnitId);
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
//adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
topView.loadAd(adRequestBuilder.build());
AdRequest.Builder adRequestBuilder1 = new AdRequest.Builder();
adRequestBuilder1.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
bottomView.loadAd(adRequestBuilder1.build());
crateInterestial();
// Do the stuff that initialize() would do for you
callForInitializeForView();
}
您可以检查此项目是否与LibGDX集成了Ad(带有或不带有Firebase,RevMob,Chartboost,StartApp …的AdMob)。
我正在尝试将AdMob广告整合到我的android应用程序中。当我使用测试模式(将我的设备定义为带有设备id的测试设备)时,广告加载非常完美。但当我退出测试模式时,广告不会出现。 这是我得到的错误: 我搜索了这个错误的含义。我发现没有添加负载。人们告诉我,如果我的帐户是新的,我必须等待1天,以显示广告。但我14天前创建了AdMob帐户。到目前为止,我只与测试广告工作,现在我不能加载现场广告。 有些
这是调试器在运行代码时输出的内容: 2018-11-07 22:12:42.806497-0600CoverMe[7740:78040]未能在(UITabBar)上设置(keyPath)用户定义的检查属性:[setValue: forUndecedKey:]:此类不符合密钥keyPath的键值编码。2018-11-07 22:12:42.901273-0600CoverMe[7740:78040]
它说不能解析符号AdRequest和不能解析adview。我做错了什么?在我的主活动文件中包括以下内容 此外,我还为build.gradle添加了以下内容 编辑 我现在知道问题出在哪里,但无法解决。我已经从项目结构中启用了Admob,它已经添加了 在大楼里。格雷德尔。我检查了一个横幅示例,示例在外部库中有播放服务,但它没有出现在我的应用程序中。
我总共有三个活动,我正在为每个活动实现admob,每个活动都有自己的横幅,当活动被改变时,另一个活动挂了一点,因为广告加载在后台,是否有任何方法,一个横幅出现在所有活动时,切换,以避免延迟。
NativeScript AdMob plugin Installation From the command prompt go to your app's root folder and execute: tns plugin add nativescript-admob iOS ⚠️ ⚠️ ⚠️ Important! Since version 4.0.0 it's required you
一个简单的例子,示范如何利用 AdMob 在App中添加广告。代码中有注释,适合初学者。 [Code4App.com]