在将我的项目迁移到androidx之前,我的google登录按钮可以正常工作。但是在迁移之后,当我单击“登录”按钮时,应用程序崩溃。我经历了许多StackOverflow问题,但未找到任何解决方案。请帮助我。
这是Logcat错误:
java.lang.IncompatibleClassChangeError:类'com.google.android.gms.auth.api.signin.internal.SignInHubActivity'在调用'androidx.lifecycle.Lifecycle androidx'时未实现接口'androidx.lifecycle.LifecycleOwner' .lifecycle.LifecycleOwner.getLifecycle()”(“ androidx.lifecycle.LiveData”的声明出现在/data/app/com.sumanmsoft.forwardz-1/split_lib_dependencies_apk.apk中)
mSignInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signIn();
}
});
GoogleSignInOptions gso = new
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(signup_Activity.this,gso);
private void signIn() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
// Signed in successfully, show authenticated UI.
firebaseAuthWithGoogle(account);
} catch (ApiException e) {
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
Log.w("Error", "signInResult:failed code=" + e.getStatusCode());
updateUI(null);
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d("sucess", "signInWithCredential:success");
moveTaskToBack(true);
FirebaseUser user = mAuth.getCurrentUser();
updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w("failed", "signInWithCredential:failure", task.getException());
updateUI(null);
}
// ...
}
});
}
private void updateUI(FirebaseUser o) {
if (o == null){
Toast.makeText(signup_Activity.this,"Signup Failed",Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(signup_Activity.this,"Signup Sucess",Toast.LENGTH_LONG).show();
}
}