android – Google登录requestIdToken返回null
作者:互联网
我分叉了this google示例项目并运行了android登录.
我在google开发人员控制台中设置了选项并获得了客户端ID,但是在运行项目时,id标记出现null.
完整代码是here
此代码请求id令牌.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.server_client_id))
.requestEmail()
.build();
我在设置中遗漏了什么,有什么建议.
这是日志
12-04 15:55:59.247 13251-13251/? I/SELinux: Function: selinux_android_load_priority [0], There is no sepolicy file.
12-04 15:55:59.247 13251-13251/? I/SELinux: Function: selinux_android_load_priority [1], There is no sepolicy version file.
12-04 15:55:59.247 13251-13251/? I/SELinux: Function: selinux_android_load_priority , priority version is VE=SEPF_GT-N7100_4.4.2_0033
12-04 15:55:59.247 13251-13251/? I/SELinux: selinux_android_seapp_context_reload: seapp_contexts file is loaded from /seapp_contexts
12-04 15:55:59.252 13251-13251/? D/dalvikvm: Late-enabling CheckJNI
12-04 15:55:59.362 13251-13251/com.google.samples.quickstart.signin I/dalvikvm: Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
12-04 15:55:59.362 13251-13251/com.google.samples.quickstart.signin W/dalvikvm: VFY: unable to resolve virtual method 194: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
12-04 15:55:59.362 13251-13251/com.google.samples.quickstart.signin D/dalvikvm: VFY: replacing opcode 0x6e at 0x00c8
12-04 15:55:59.367 13251-13251/com.google.samples.quickstart.signin I/dalvikvm: Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzh
12-04 15:55:59.367 13251-13251/com.google.samples.quickstart.signin W/dalvikvm: VFY: unable to resolve virtual method 453: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
12-04 15:55:59.367 13251-13251/com.google.samples.quickstart.signin D/dalvikvm: VFY: replacing opcode 0x6e at 0x000b
12-04 15:55:59.402 13251-13275/com.google.samples.quickstart.signin I/GMPM: App measurement is starting up
12-04 15:55:59.417 13251-13251/com.google.samples.quickstart.signin W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
12-04 15:55:59.417 13251-13251/com.google.samples.quickstart.signin I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onSearchRequested
12-04 15:55:59.417 13251-13251/com.google.samples.quickstart.signin W/dalvikvm: VFY: unable to resolve interface method 15687: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
12-04 15:55:59.417 13251-13251/com.google.samples.quickstart.signin D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
12-04 15:55:59.422 13251-13251/com.google.samples.quickstart.signin I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode
12-04 15:55:59.422 13251-13251/com.google.samples.quickstart.signin W/dalvikvm: VFY: unable to resolve interface method 15691: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
12-04 15:55:59.422 13251-13251/com.google.samples.quickstart.signin D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
12-04 15:55:59.462 13251-13251/com.google.samples.quickstart.signin I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
12-04 15:55:59.462 13251-13251/com.google.samples.quickstart.signin W/dalvikvm: VFY: unable to resolve virtual method 528: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
12-04 15:55:59.462 13251-13251/com.google.samples.quickstart.signin D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
12-04 15:55:59.462 13251-13251/com.google.samples.quickstart.signin I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
12-04 15:55:59.462 13251-13251/com.google.samples.quickstart.signin W/dalvikvm: VFY: unable to resolve virtual method 550: Landroid/content/res/TypedArray;.getType (I)I
12-04 15:55:59.462 13251-13251/com.google.samples.quickstart.signin D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
12-04 15:55:59.512 13251-13251/com.google.samples.quickstart.signin D/AbsListView: Get MotionRecognitionManager
12-04 15:55:59.567 13251-13251/com.google.samples.quickstart.signin D/libEGL: loaded /system/lib/egl/libEGL_mali.so
12-04 15:55:59.567 13251-13251/com.google.samples.quickstart.signin D/libEGL: loaded /system/lib/egl/libGLESv1_CM_mali.so
12-04 15:55:59.572 13251-13251/com.google.samples.quickstart.signin D/libEGL: loaded /system/lib/egl/libGLESv2_mali.so
12-04 15:55:59.637 13251-13251/com.google.samples.quickstart.signin D/OpenGLRenderer: Enabling debug mode 0
12-04 15:56:12.417 13251-13251/com.google.samples.quickstart.signin D/IdTokenActivity: onActivityResult:GET_TOKEN:success:false
12-04 15:56:48.477 13251-13257/com.google.samples.quickstart.signin D/dalvikvm: GC_FOR_ALLOC freed 707K, 17% free 9803K/11764K, paused 34ms, total 34ms
顶级构建脚本
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
应用级构建脚本
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.google.samples.quickstart.signin"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'LICENSE.txt'
}
// Resolve dependency differences between app and tests
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:23.1.1'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
// Dependency for Google Sign-In
compile 'com.google.android.gms:play-services-auth:8.3.0'
// UiAutomatorTesting
androidTestCompile 'com.android.support.test:runner:0.2'
androidTestCompile 'com.android.support.test:rules:0.2'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.0'
androidTestCompile 'com.android.support:support-annotations:23.1.1'
}
google-services.json文件
{
"project_info": {
"project_id": "se....-la..da-......",
"project_number": "6043........",
"name": "Demo"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:6.3....24..:and..id:f62.........40e",
"client_id": "android:com.example.googlesignindemo",
"client_type": 1,
"android_client_info": {
"package_name": "com.example.googlesignindemo"
}
},
"oauth_client": [
{
"client_id": "604...430-uho...slp......v2l........d9...ps.g.....leu........com",
"client_type": 1,
"android_info": {
"package_name": "com.example.googlesignindemo",
"certificate_hash": "mysha1 fingerprint from debug keystore"
}
}
],
"api_key": [],
"services": {
"analytics_service": {
"status": 1
},
"cloud_messaging_service": {
"status": 1,
"apns_config": []
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"google_signin_service": {
"status": 2
},
"ads_service": {
"status": 1
}
}
}
],
"client_info": [],
"ARTIFACT_VERSION": "1"
}
解决方法:
正如我所评论的那样,作为Google的文档,您应该使用“Web应用程序”类型的客户端ID,而不是“Android”类型的客户端ID.
如下截图:
标签:android,google-play-services,google-signin 来源: https://codeday.me/bug/20190928/1827117.html