无法在我的应用中使用Google登录,选择帐户进行登录后,我会收到nullpointerexception和IncompatibleClassChangeError
我尝试将.requestIdToken()添加到构建器中,但没有帮助
登录:
if (GoogleSignIn.getLastSignedInAccount(this) == null){
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken("token")
.requestScopes(new Scope(Scopes.DRIVE_APPFOLDER))
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, 1);
}
onActivityResult:
if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
handleSignInResult:
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
} catch (ApiException e) {
Log.e(TAG, "handleSignInResult:error \n\n", e);
Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
build.gradle中的依赖项:
configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.core:core:1.1.0-alpha03"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
implementation 'com.jaredrummler:colorpicker:1.0.5'
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
// Dependency for Google Sign-In
implementation 'com.google.android.gms:play-services-auth:16.0.1'
// Dependencies for the REST API example
implementation 'com.google.api-client:google-api-client:1.25.0'
implementation 'com.google.api-client:google-api-client-android:1.23.0'
implementation 'com.google.apis:google-api-services-people:v1-rev139-1.22.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation "androidx.core:core-ktx:+"
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
}
日志:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.f0x1d.notes, PID: 19170
java.lang.IncompatibleClassChangeError: Class 'com.google.android.gms.auth.api.signin.internal.SignInHubActivity' does not implement interface 'androidx.lifecycle.h' in call to 'androidx.lifecycle.f androidx.lifecycle.h.c()' (declaration of 'androidx.lifecycle.LiveData' appears in /data/app/com.f0x1d.notes-d3tALwcyOU5P4KuqMXk6tQ==/base.apk)
01-21 20:06:40.227 E/AndroidRuntime(8984): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=40962, result=-1, data=Intent { (has extras) }} to activity {com.f0x1d.notes/com.google.android.gms.auth.api.signin.internal.SignInHubActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.lifecycle.f$b androidx.lifecycle.f.a()' on a null object reference