【问题标题】:GoogleApiClient error in lollipop and earlier versions棒棒糖和早期版本中的 GoogleApiClient 错误
【发布时间】:2017-09-20 03:41:24
【问题描述】:

一段时间以来,我一直在尝试使用 android studio 中的 BaseGameUtils 在我的 libgdx 游戏中实现 google play 游戏服务,这可以正常工作并正确初始化,但仅限于最新版本的 android,如 Oreo 或 Nougat。早期版本在应用打开后立即显示以下异常:

E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.xx.mygame, PID: 1234
        java.lang.VerifyError: com/google/android/gms/common/api/GoogleApiClient$Builder
              at com.google.example.games.basegameutils.GameHelper.createApiClientBuilder(GameHelper.java:260)
              at com.google.example.games.basegameutils.GameHelper.setup(GameHelper.java:297)
              at com.xx.mygame.AndroidLauncher.onCreate(AndroidLauncher.java:31)
              at android.app.Activity.performCreate(Activity.java:5231)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
              at android.app.ActivityThread.access$800(ActivityThread.java:135)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:136)
              at android.app.ActivityThread.main(ActivityThread.java:5017)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
              at dalvik.system.NativeStart.main(Native Method)

我一直在调查 BaseGameUtils 模块的文件,试图找出问题所在,但我无能为力。任何帮助表示赞赏

这是 build.gradle 文件:

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-arm64-v8a"
    natives "com.badlogicgames.gdx:gdx-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-arm64-v8a"
    natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
    natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
    compile "com.android.support:support-core-utils:26.0.0"
    compile 'com.google.android.gms:play-services-base:11.0.4'
    compile "com.google.android.gms:play-services-games:11.0.4"
    compile project(":BaseGameUtils")
}}

Build.gradle(模块:BaseGameUtils)

    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.4.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.build_tools_version = "23.0.2"
    }
    // Set defaults so that BaseGameUtils can be used outside of BasicSamples
    if (!project.hasProperty('android_min_sdk_version')) {
        // Google Play Services minimum requirements is 14
        ext.android_min_sdk_version = 14
    }

    compileSdkVersion android_compile_version
    buildToolsVersion "25.0.2"

    defaultConfig {
        minSdkVersion android_min_sdk_version
        targetSdkVersion android_compile_version
    }
}

【问题讨论】:

  • 显示build.gradle 对android 有依赖关系的文件,例如build.gradle 文件BaseGameUtils 和android 模块。
  • @AbhishekAryan 好的,我已经粘贴了 build.gradle!

标签: android android-studio libgdx google-play-services


【解决方案1】:

版本不匹配/工件冲突。

为什么同一工件有两个版本。您在项目根 build.gradle 文件中注入了 play-services-games 的版本 11.0.4BaseGameUtils 模块的 build.gradle 文件中相同工件的版本 8.4.0

因此,在整个项目中保留任何工件的一个版本,或者最好是最新版本。目前是11.2.2


  • 所以从根build.gradle文件中删除play-service依赖
  • BaseGameUtilsbuild.gradle文件中的gms库版本更新为11.2.2
  • 在存储库列表中添加 Google 的 Maven 存储库,从版本 11.2.0 工件现在可在 Google maven 存储库中获得。

    repositories {
       maven { url "https://maven.google.com/" }
    }
    

【讨论】:

  • 哦,f*ck,谢谢,我已经更新了 BaseGameUtils 中的 gms 库,并删除了根 gradle 中的播放服务和支持依赖项,现在它可以工作了。祝福兄弟!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-15
  • 1970-01-01
  • 1970-01-01
  • 2015-06-06
  • 1970-01-01
相关资源
最近更新 更多