【问题标题】:Android GoogleApiClient connects to MARSHMALLOW but not to JELLY_BEANAndroid GoogleApiClient 连接到 MARSHMALLOW 但不连接到 JELLY_BEAN
【发布时间】:2017-12-20 01:38:50
【问题描述】:

我的 Android 应用将文件转储到 Gdrive 中。它使用 Oauth2.0 身份验证,我已经在 console.developers.google.com 上完成了必要的工作。我面临的问题是该应用程序在我的 Marshmallow 手机上运行良好,但无法通过我的 JellyBean 或更低版本的 Google 登录。在这些情况下,应用会卡在“选择帐户”窗口。

Studio 的 Android 监视器返回以下内容:

GoogleApiClient connection failed: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{419cbb80 ...

请记住,该应用确实可以在 Marshmallow 手机上运行,​​我怀疑该问题与该应用的 build.grade 文件中的“版本”之一有关,下面是其中的摘录。

compileSdkVersion 23
buildToolsVersion "26.0.0"

defaultConfig {
    applicationId "rudy.android.stgpro"
    minSdkVersion 9
    targetSdkVersion 18
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.rudykeystore
    }
    debug {
        signingConfig signingConfigs.rudykeystore
    }
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.google.android.gms:play-services-drive:8.4.0'
}

或者,也许 Oauth2.0 不适用于早期的 Android 版本。

我还注意到,加载到 Marshmallow 中的应用大小大约是加载到其他两部手机中的大小的 40%。

Google 的云端硬盘应用可在所有手机上正常运行。

我已经在谷歌上搜索了几个小时,而且几乎被卡住了。有什么建议吗?

【问题讨论】:

  • Jelly Bean 是 Android 16 版本,但你的 targetSdkVersion 设置为 18。尝试将其设置为 16,根据Android 4.1 APIs docs。确保 Android Studio 也有 Android 16 的必要更新。
  • 试过了......没有运气。其实我已经试过好几种compileSdkVersion、minSdkVersion、targetSdkVersion、play-services-drive的组合了。

标签: android oauth-2.0 google-drive-api


【解决方案1】:

经过“血、汗和泪”,我发现问题出在 AndroidManifest.xml 文件中的一行...

android:launchMode="singleInstance"

我不知道为什么这条线路会影响运行 JellyBean 和更低版本但不影响 Marshmallow 的手机(不确定 Kitkat 和 Lollipop)。而且,为了清楚起见,这行字面意思是用它的存在/不存在来切换问题(其他变化为零)。

我以Drives's Quickstart 为基础解决了这个问题(它的连接适用于我所有的测试手机),然后通过在我的应用程序代码中添加/删除来逐步修改它的代码(花了我几天时间)。

无论如何,感谢上帝提供这些工作样本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    相关资源
    最近更新 更多