UPD:我通过改变
中GameHelper构造函数的使用来解决问题gameHelper = new GameHelper(this, GameHelper.CLIENT_ALL);
到
gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES);
但我不知道为什么它会有所帮助。如果有人向我解释,我会很高兴。)
我在向我的libGDX项目添加baseGameUtils时遇到了问题。 Gradle链接工作正常,但是当我运行游戏时,apk构建失败。 Gradle控制台消息:
Executing tasks: [:android:assembleDebug]
Configuration on demand is an incubating feature.
:android:preBuild UP-TO-DATE
:android:preDebugBuild UP-TO-DATE
:android:checkDebugManifest
:android:preReleaseBuild UP-TO-DATE
:core:compileJava UP-TO-DATE
:core:processResources UP-TO-DATE
:core:classes UP-TO-DATE
:core:jar UP-TO-DATE
:libraries:BaseGameUtils:compileLint
:libraries:BaseGameUtils:copyReleaseLint UP-TO-DATE
:libraries:BaseGameUtils:preBuild UP-TO-DATE
:libraries:BaseGameUtils:preReleaseBuild UP-TO-DATE
:libraries:BaseGameUtils:checkReleaseManifest
:libraries:BaseGameUtils:preDebugAndroidTestBuild UP-TO-DATE
:libraries:BaseGameUtils:preDebugBuild UP-TO-DATE
:libraries:BaseGameUtils:preDebugUnitTestBuild UP-TO-DATE
:libraries:BaseGameUtils:preReleaseUnitTestBuild UP-TO-DATE
:libraries:BaseGameUtils:prepareComAndroidSupportAppcompatV72000Library UP-TO-DATE
:libraries:BaseGameUtils:prepareComAndroidSupportSupportV42100Library UP-TO-DATE
:libraries:BaseGameUtils:prepareComGoogleAndroidGmsPlayServices6587Library UP-TO-DATE
:libraries:BaseGameUtils:prepareReleaseDependencies
:libraries:BaseGameUtils:compileReleaseAidl UP-TO-DATE
:libraries:BaseGameUtils:compileReleaseRenderscript UP-TO-DATE
:libraries:BaseGameUtils:generateReleaseBuildConfig UP-TO-DATE
:libraries:BaseGameUtils:generateReleaseAssets UP-TO-DATE
:libraries:BaseGameUtils:mergeReleaseAssets UP-TO-DATE
:libraries:BaseGameUtils:generateReleaseResValues UP-TO-DATE
:libraries:BaseGameUtils:generateReleaseResources UP-TO-DATE
:libraries:BaseGameUtils:mergeReleaseResources UP-TO-DATE
:libraries:BaseGameUtils:processReleaseManifest UP-TO-DATE
:libraries:BaseGameUtils:processReleaseResources UP-TO-DATE
:libraries:BaseGameUtils:generateReleaseSources UP-TO-DATE
:libraries:BaseGameUtils:processReleaseJavaRes UP-TO-DATE
:libraries:BaseGameUtils:compileReleaseJava UP-TO-DATE
:libraries:BaseGameUtils:extractReleaseAnnotations UP-TO-DATE
:libraries:BaseGameUtils:mergeReleaseProguardFiles UP-TO-DATE
:libraries:BaseGameUtils:packageReleaseJar UP-TO-DATE
:libraries:BaseGameUtils:compileReleaseNdk UP-TO-DATE
:libraries:BaseGameUtils:packageReleaseJniLibs UP-TO-DATE
:libraries:BaseGameUtils:packageReleaseLocalJar UP-TO-DATE
:libraries:BaseGameUtils:packageReleaseRenderscript UP-TO-DATE
:libraries:BaseGameUtils:packageReleaseResources UP-TO-DATE
:libraries:BaseGameUtils:bundleRelease UP-TO-DATE
:android:prepareComAndroidSupportAppcompatV72000Library UP-TO-DATE
:android:prepareComAndroidSupportSupportV42100Library UP-TO-DATE
:android:prepareComGoogleAndroidGmsPlayServices6587Library UP-TO-DATE
:android:prepareTestLibrariesBaseGameUtils10Library UP-TO-DATE
:android:prepareDebugDependencies
:android:compileDebugAidl UP-TO-DATE
:android:compileDebugRenderscript UP-TO-DATE
:android:generateDebugBuildConfig UP-TO-DATE
:android:generateDebugAssets UP-TO-DATE
:android:mergeDebugAssets UP-TO-DATE
:android:generateDebugResValues UP-TO-DATE
:android:generateDebugResources UP-TO-DATE
:android:mergeDebugResources UP-TO-DATE
:android:processDebugManifest UP-TO-DATE
:android:processDebugResources UP-TO-DATE
:android:generateDebugSources UP-TO-DATE
:android:processDebugJavaRes UP-TO-DATE
:android:compileDebugJava
:android:compileDebugNdk UP-TO-DATE
:android:compileDebugSources
:android:preDexDebug
:android:dexDebug
AGPBI: {"kind":"SIMPLE","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","position":{},"original":"UNEXPECTED TOP-LEVEL EXCEPTION:"}
AGPBI: {"kind":"SIMPLE","text":"java.lang.IllegalArgumentException: method ID not in [0, 0xffff]: 65536","position":{},"original":"java.lang.IllegalArgumentException: method ID not in [0, 0xffff]: 65536"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:501)","position":{},"original":"\tat com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:501)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:282)","position":{},"original":"\tat com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:282)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:490)","position":{},"original":"\tat com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:490)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:167)","position":{},"original":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:167)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:188)","position":{},"original":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:188)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)","position":{},"original":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)","position":{},"original":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.run(Main.java:230)","position":{},"original":"\tat com.android.dx.command.dexer.Main.run(Main.java:230)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.main(Main.java:199)","position":{},"original":"\tat com.android.dx.command.dexer.Main.main(Main.java:199)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.Main.main(Main.java:103)","position":{},"original":"\tat com.android.dx.command.Main.main(Main.java:103)"}
FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':android:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 2
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
我发现如果我评论在BaseGameUtils的build.gradle中编译com.android.support:appcompat-v7库比游戏工作正常,但是当我尝试从游戏登录google-play时我遇到了崩溃。它可能是我的代码中的错误,但从BaseGameUtils中排除依赖appcompat-v7是不对的。我应该怎么做才能用它来构建我的游戏?
android {
buildToolsVersion "22.0.1"
compileSdkVersion 22
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')
}
}
// 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/x86/").mkdirs();
configurations.natives.files.each { jar ->
def outputDir = null
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.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.mygdx.game.android/com.mygdx.game.android.AndroidLauncher'
}
// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
// need to specify Java source sets explicitely, 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")
}
}
}
}
}
}
}
dependencies {
compile project(':BaseGameUtils')
}
以下是登录尝试失败时logcat显示的内容:
09-12 01:26:21.084 15670-15670 / ru.zuko.game.android D / GameHelper:GameHelper:beginUserInitiatedSignIn:重置尝试次数。
09-12 01:26:21.084 15670-15670 / ru.zuko.game.android D / GameHelper:GameHelper:启动用户启动的登录流程。
09-12 01:26:21.084 15670-15670 / ru.zuko.game.android D / GameHelper:GameHelper:beginUserInitiatedSignIn:开始新的登录流程。
09-12 01:26:21.084 15670-15670 / ru.zuko.game.android D / GameHelper:GameHelper:开始连接。
09-12 01:26:21.184 15670-15670 / ru.zuko.game.android D / AndroidRuntime:关闭VM 09-12 01:26:21.184 15670-15670 / ru.zuko.game.android W / dalvikvm:threadid = 1:线程退出未捕获异常(组= 0xb0cfcb20)
09-12 01:26:21.184 15670-15670 / ru.zuko.game.android E / AndroidRuntime:致命例外:主要
流程:ru.zuko.game.android,PID:15670
java.lang.IllegalStateException:发生了致命的开发人员错误。查看日志以获取更多信息 在com.google.android.gms.internal.jl $ h.b(未知来源)
在com.google.android.gms.internal.jl $ h.g(未知来源)
在com.google.android.gms.internal.jl $ b.hy(未知来源)
在com.google.android.gms.internal.jl $ a.handleMessage(未知来源)
在android.os.Handler.dispatchMessage(Handler.java:102)
在android.os.Looper.loop(Looper.java:136)
在android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
在java.lang.reflect.Method.invoke(Method.java:515)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
在dalvik.system.NativeStart.main(本地方法)
答案 0 :(得分:0)
我不知道你是如何将BaseGameUtils添加到你的项目中的,但添加对我有用的最佳方法是将整个包从BaseGameUtils复制粘贴到你的game-android项目中。您可以从您自己的项目中引用您的Helper类。[GameHelper,GameHelperUtils]无需为2个java文件添加不同的项目作为依赖项。如果需要,您还可以删除无用的活动代码。
也可以在gradle依赖中使用play服务,而不是添加为库,以防你不再这样做。