首页 > 解决方案 > Google登录失败Firease身份验证android

问题描述

我创建了一个应用程序,今天上传到 alpha 测试轨道。但我面临一些问题。我已经实现了 firebase 身份验证(Google 登录)。将应用程序上传到 Play 商店后,谷歌登录失败(在将应用程序上传到 Play 商店之前,身份验证工作正常)。

这是代码(谷歌登录)

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

        mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

signInButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                signIn();
            }
        });

private void signIn() {

        Intent signInIntent = mGoogleSignInClient.getSignInIntent();
        startActivityForResult(signInIntent, RC_SIGN_IN);

    }

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

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

    }

    private void handleSignIn(Task<GoogleSignInAccount> completedTask) {

        try {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = completedTask.getResult(ApiException.class);
            Toast.makeText(this, "success", Toast.LENGTH_SHORT).show();
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            // Google Sign In failed, update UI appropriately
            Log.e("TAG_failure", "Google sign in failed");
            Toast.makeText(this, "Failed", Toast.LENGTH_SHORT).show();
        }

    }

    private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {

        loadingDialog.show();

        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()) {
                            loadingDialog.dismiss();
                            Log.d("TAG_S", "signInWithCredential:success");
                            FirebaseUser user = mAuth.getCurrentUser();
                            //firebaseDataHandler();
                            queryData();
                            authLayout.setVisibility(View.GONE);
                        } else {
                            // If sign in fails, display a message to the user.
                            Log.e("TAG_F", "signInWithCredential:failure", task.getException());
                            //updateUI(null);
                            loadingDialog.dismiss();
                        }
                    }
                });
    }

这是build.gradle

buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
    }

而且在将应用上传到游戏机后,谷歌应用内购买也不起作用

proguard-rules.pro我添加了这一行

-keep class com.android.vending.billing.**

我还添加了计费权限,但我不知道为什么这不起作用

<uses-permission android:name="com.android.vending.BILLING" />

有什么我不知道的令人困惑的问题。

提前感谢您的帮助。

标签: javaandroidfirebase

解决方案


我添加了这些行,问题解决了

proguard-rules.pro

-keepattributes Signature
-keepattributes *Annotation*

-dontnote com.google.**

-keep class persistence.** {
  *;
}

-keep class com.firebase.** { *; }

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-keep class com.android.vending.billing.**


推荐阅读