以非零退出值完成 2 BaseGameServices 和 Admob
Posted
技术标签:
【中文标题】以非零退出值完成 2 BaseGameServices 和 Admob【英文标题】:Finished with non-zero exit value 2 BaseGameServices and Admob 【发布时间】:2016-03-25 10:22:52 【问题描述】:您好,我使用 Libgdx 开发了一款游戏,在我决定添加排行榜之前,一切似乎都可以正常运行。
我在互联网上进行了研究,但没有找到正确的解决方案。起初我认为问题在于我拥有的图书馆数量。但后来我意识到问题出在使用 Admob 和 BaseGameUtils(以一种简单的方式使用 GameServices 的库),因为我决定删除我的项目的依赖项以查看它是否有效。
compile "com.google.android.gms:play-services-ads:$admobVersion"
一切正常。
你知道为什么 Admob 依赖项和 BaseGameUtils 项目不能一起工作吗?提前谢谢大家。
这里是项目的build.gradle:
buildscript
repositories
mavenCentral()
maven url "https://oss.sonatype.org/content/repositories/snapshots/"
dependencies
classpath 'com.android.tools.build:gradle:1.3.0'
allprojects
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.0'
ext
appName = "TheCavern"
gdxVersion = '1.7.1'
roboVMVersion = '1.9.0'
box2DLightsVersion = '1.4'
ashleyVersion = '1.6.0'
aiVersion = '1.6.0'
admobVersion = '8.3.0'
repositories
mavenCentral()
maven url "https://oss.sonatype.org/content/repositories/snapshots/"
maven url "https://oss.sonatype.org/content/repositories/releases/"
project(":desktop")
apply plugin: "java"
dependencies
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
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.box2dlights:box2dlights:$box2DLightsVersion"
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:$admobVersion"
compile project(":BaseGameUtils")
project(":core")
apply plugin: "java"
dependencies
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
tasks.eclipse.doLast
delete ".project"
这里是 BaseGameUtils 库的 build.gradle。
apply plugin: 'com.android.library'
buildscript
repositories
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:1.3.1'
dependencies
// Set defaults so that BaseGameUtils can be used outside of BasicSamples
if (!project.hasProperty('appcompat_library_version'))
ext.appcompat_library_version = '20.0.+'
if (!project.hasProperty('support_library_version'))
ext.support_library_version = '20.0.+'
if (!project.hasProperty('gms_library_version'))
ext.gms_library_version = '8.1.0'
compile "com.android.support:appcompat-v7:$appcompat_library_version"
compile "com.android.support:support-v4:$support_library_version"
compile "com.google.android.gms:play-services-games:$gms_library_version"
compile "com.google.android.gms:play-services-plus:$gms_library_version"
android
// Set defaults so that BaseGameUtils can be used outside of BasicSamples
if (!project.hasProperty('android_compile_version'))
ext.android_compile_version = 23
if (!project.hasProperty('android_version'))
ext.android_version = '23'
compileSdkVersion android_compile_version
buildToolsVersion android_version
最后,这是我尝试在手机中测试应用程序时遇到的错误。
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzlv;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':android:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 2
【问题讨论】:
【参考方案1】:我发布答案只是因为它可能对遇到同样问题的人有用。问题出现是因为在我的项目的 build.graddle 中我使用的是库版本 8.3.0
ext.gms_library_version = '8.3.0'
compile "com.google.android.gms:play-services-games:$gms_library_version"
但是在 BaseGameUtils 的 build.graddle 中使用的是 8.1.0 版
if (!project.hasProperty('gms_library_version'))
ext.gms_library_version = '8.1.0'
compile "com.google.android.gms:play-services-games:$gms_library_version"
compile "com.google.android.gms:play-services-plus:$gms_library_version"
所以我只是将我的项目的 build.graddle 的版本更改为 8.1.0 以使两个项目具有相同的版本并且它可以工作。
ext.gms_library_version = '8.1.0'
compile "com.google.android.gms:play-services-games:$gms_library_version"
现在似乎一切正常。
【讨论】:
奖金,即使这不是最终答案。明确说明如何设置 gradle 项目属性并演示它在另一个项目中的使用!以上是关于以非零退出值完成 2 BaseGameServices 和 Admob的主要内容,如果未能解决你的问题,请参考以下文章
异常:Gradle 任务 assembleDebug 失败,退出代码 1 以非零退出值 1 完成