使用Google登录时显示验证运行时错误

时间:2019-06-28 12:17:37

标签: android firebase google-cloud-firestore google-signin

在Google在Android Firebase中通过Google登录时显示验证错误。我添加了对Google Sign的所有依赖关系,但仍在运行时显示了验证错误,我将此应用与Firebase连接以使用Google登录登录

主要活动

public class MainActivity extends AppCompatActivity {

SignInButton signInButton;
private GoogleApiClient googleApiClient;
private FirebaseAuth mAuth;
TextView textView;
private static final int GOOGLE_SIGN = 1;
GoogleSignInClient mGoogleSignInClent;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mAuth = FirebaseAuth.getInstance();

   /* googleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this,this)
            .addApi(mAuth.GOOGLE_SIGN_IN_API,gso)
            .build();*/

    GoogleSignInOptions gso = new GoogleSignInOptions
            .Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build();

    mGoogleSignInClent = GoogleSignIn.getClient(this,gso);




    SignInButton signInButton = findViewById(R.id.sign_in_button);
    signInButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            signIn();
        }
    });

    if(mAuth.getCurrentUser()!=null)
    {
        FirebaseUser user = mAuth.getCurrentUser();
        update(user);
    }

}



private void signIn()
{
    Intent signInIntent = mGoogleSignInClent.getSignInIntent();
    startActivityForResult(signInIntent, GOOGLE_SIGN);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == GOOGLE_SIGN)
    {
        Task<GoogleSignInAccount> task =GoogleSignIn.getSignedInAccountFromIntent(data);

        try
        {
            GoogleSignInAccount account = task.getResult(ApiException.class);
            if(account != null)
                firebaseAuthWithGoogle(account);

        }
        catch(Exception e)
        {
            Log.e("error",e.toString());
        }
    }
}

private void firebaseAuthWithGoogle(GoogleSignInAccount account)
{
    AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(),null);
    mAuth.signInWithCredential(credential).addOnCompleteListener(this, task -> {
        if(task.isSuccessful())
        {
            FirebaseUser user = mAuth.getCurrentUser();
            update(user);
        }
        else
        {
            Toast.makeText(this,"error",Toast.LENGTH_SHORT).show();
            update(null);
        }
    });
}

private void update(FirebaseUser user)
{
    if(user != null)
    {
        String name = user.getDisplayName();
        String email = user.getEmail();
        Toast.makeText(this,""+name+" "+email,Toast.LENGTH_SHORT).show();
    }
}
}

Gradle

implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-storage:16.0.4'
implementation 'com.google.firebase:firebase-firestore:17.1.2'
implementation 'com.google.firebase:firebase-core:16.0.5'
testImplementation 'junit:junit:4.12'
implementation 'com.google.android.gms:play-services-auth:12.0.1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

mainactivity.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".UI.MainActivity"
android:orientation="horizontal">

<com.google.android.gms.common.SignInButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/sign_in_button"
    android:layout_marginLeft="110dp"
    android:layout_gravity="center"
    app:buttonSize="wide"></com.google.android.gms.common.SignInButton>


</LinearLayout>

在运行时显示此错误,让我知道是什么问题

  

E / AndroidRuntime:致命异常:主要

     

进程:com.example.coludfirestore,PID:31004

     

java.lang.VerifyError:验证者拒绝了com.google.android.gms.auth.api.signin.GoogleSignInClient类:int com.google.android.gms.auth.api.signin.GoogleSignInClient.zzach()失败验证:int com.google.android.gms.auth.api.sign.GoogleSignInClient.zzach():[0xF]'this'自变量'参考:com.google.android.gms.common.GoogleApiAvailability'不是'Precise'实例参考:com.google.android.gms.common.zzf”(“ com.google.android.gms.auth.api.signin.GoogleSignInClient”的声明出现在/data/app/com.example.coludfirestore-mlIQUAwJCuv8NfVJG2UK8g== /split_lib_dependencies_apk.apk)           位于com.google.android.gms.auth.api.signin.GoogleSignIn.getClient(未知来源:0)           在com.example.coludfirestore.UI.MainActivity.onCreate(MainActivity.java:56)

0 个答案:

没有答案