J'ai ajouté this google exemple de projet et lancé le code de connexion Android.
J'ai configuré les options dans la console des développeurs google et obtenu un identifiant client, mais lors de l'exécution du projet, le jeton d'identifiant est null.
Le code complet est ici
Ce code demande le jeton id.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.server_client_id))
.requestEmail()
.build();
Est-ce que quelque chose me manque dans la configuration, des suggestions?
Voici le journal
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
Script de construction de niveau supérieur
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()
}
}
Script de construction au niveau de l'application
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'
}
fichier 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"
}
Utilisez "default_web_client_id" dans GoogleSignInOptions
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
Ça fonctionne parfaitement.
Dans mon cas, c’était juste la version incompatible des bibliothèques ... :(