在Android应用中,Google登录弹出窗口无法加载

每当我尝试通过启动谷歌登录意图登录时,它直接转到onActivityResult,而我没有机会选择一个帐户.
所有它确实是屏幕上的dimm,但选择帐户的窗口没有显示.
然后登录失败,出现此ApiException:

java.lang.classNotFoundException: com.google.android.gms.common.api.Scope

java.lang.RuntimeException: Canvas: trying to draw too large(256000000bytes) bitmap.

(完整堆栈跟踪:https://pastebin.com/vBZeBLu0)

我所有使用的依赖项都是最新的,我的凭据(oAuth client-id)都设置正确,我尝试了其他类似问题的解决方案,但没有一个解决了我的问题,我还检查了用户是否已注销完全来自设备,问题不断重现.

这是我的登录活动:

public class Login extends Activity implements Googleapiclient.OnConnectionFailedListener, Googleapiclient.ConnectionCallbacks  {                                   

private static final String TAG = "LoginProcess";

SignInButton gsignInButton;
private static final int RC_SIGN_IN = 1;
DatabaseReference mRef;
FirebaseAuth mAuth;
FirebaseAuth.AuthStateListener mAuthListener;
GoogleSignInoptions gso;
Googleapiclient mGoogleapiclient;


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

    mAuth = FirebaseAuth.getInstance();



    gso = new GoogleSignInoptions.Builder(GoogleSignInoptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestemail()
            .build();

    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

    gsignInButton = findViewById(R.id.sib);

    gsignInButton.setColorScheme(SignInButton.COLOR_DARK); // wide button style
    gsignInButton.setonClickListener(myhandler);


}

View.OnClickListener myhandler = new View.OnClickListener() {
    public void onClick(View v) {
       signIn();
    }

};



public 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);

    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            // Google Sign In Failed, update UI appropriately
            Log.w(TAG, "Google sign in Failed", e);  //this is where it always lands.
            Toast.makeText(this, "login Failed", Toast.LENGTH_SHORT).show();
            // ...
        }
    }

}

登录活动的完整代码https://pastebin.com/6Yi7vzD7

摇篮:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsversion '28.0.3'

    defaultConfig {
        applicationId "com.example.sanchez.worldgramproject"
        minSdkVersion 21
        targetSdkVersion 28
        multiDexEnabled true
        versionCode 0
        versionName "0"


    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }
}



dependencies {

    compile filetree(dir: 'libs', include: ['*.jar'])
    api "com.google.android.material:material:1.0.0"

    implementation 'com.github.madrapps:pikolo:1.1.6'
    implementation 'com.google.android.gms:play-services-drive:16.0.0'
    implementation 'com.google.android.material:material:1.1.0-alpha02'
    implementation 'com.github.bumptech.glide:glide:3.8.0'
    implementation'com.firebaseui:firebase-ui-storage:2.3.0'
    implementation 'com.google.firebase:firebase-auth:16.1.0'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.jakewharton:butterknife:8.8.1'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.6'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.exifinterface:exifinterface:1.0.0'
    implementation 'com.google.firebase:firebase-storage:16.0.5'
    implementation 'com.google.android.gms:play-services-maps:16.0.0'
    implementation 'com.google.firebase:firebase-database:16.0.5'
    testImplementation 'junit:junit:4.12'

}


apply plugin: 'com.google.gms.google-services'

我不知道问题的原因是什么,如何解决这个问题并弹出帐户选择窗口?

编辑2.1.2019

而不是上面的ApiExeption我得到这个错误

W/LoginProcess: Google sign in Failed
    com.google.android.gms.common.api.ApiException: 8: 
        at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(UnkNown Source:4)
        at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(UnkNown Source:8)
        at com.example.sanchez.worldgramproject.Login.onActivityResult(Login.java:162)
        at android.app.Activity.dispatchActivityResult(Activity.java:7548)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4485)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4532)
        at android.app.ActivityThread.-wrap20(UnkNown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1752)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6938)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

我相信我设置oAuth的方式出了问题(由Firebase生成自动)

解决方法:

选项1 – 确保在Firebase控制台的Firebase身份验证方法中启用了Google登录.认情况下,未启用Google登录.

选项2 – 在AndroidManifest.xml文件中,在标记添加以下行以支持高内存支持,以防Google登录弹出窗口需要更多内存.甚至可以在应用程序标记中使用此命令加载大图像 – largeHeap为true~在这种情况下为您的启动器图像.

<application
    android:hardwareAccelerated="true"
    android:largeHeap="true" >

选项3 – 尝试使用此代码来使用Firebase实施Google登录,它应该可以正常运行.

public class LoginActivity extends AppCompatActivity {

private GoogleSignInClient mGoogleSignInClient;
private FirebaseAuth mAuth;
private int permissions = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    SignInButton authButton = findViewById(R.id.home_auth_button);
    GoogleSignInoptions gso = new GoogleSignInoptions.Builder(GoogleSignInoptions.DEFAULT_SIGN_IN)
            .requestIdToken("xxxxxxxxxxxx.apps.googleusercontent.com").requestemail().build();
    mAuth = FirebaseAuth.getInstance();
    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
    authButton.setonClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            signIn();
        }
    });
}

private void signIn() {
    Intent signInIntent = mGoogleSignInClient.getSignInIntent();
    startActivityForResult(signInIntent, 0);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 0) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            GoogleSignInAccount account = task.getResult(ApiException.class);
            if (account != null) {
                firebaseAuthWithGoogle(account);
            } else{
                Log.w("AUTH", "Account is NULL");
                Toast.makeText(LoginActivity.this, "Sign-in Failed, try again later.", Toast.LENGTH_LONG).show();
            }
        } catch (ApiException e) {
            Log.w("AUTH", "Google sign in Failed", e);
            Toast.makeText(LoginActivity.this, "Sign-in Failed, try again later.", Toast.LENGTH_LONG).show();
        }
    }
}

private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d("AUTH", "firebaseAuthWithGoogle:" + acct.getId());
    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()) {
                        Log.d("AUTH", "signInWithCredential:success");
                        startActivity(new Intent(LoginActivity.this, AnotherActivity.class));
                        Toast.makeText(LoginActivity.this, "Sign-in successful!", Toast.LENGTH_LONG).show();
                    } else {
                        Log.w("AUTH", "signInWithCredential:failure", task.getException());
                        Toast.makeText(LoginActivity.this, "Sign-in Failed, try again later.", Toast.LENGTH_LONG).show();
                    }
                }
            });
    }
}

请注意您需要使用构建器传递requestIdToken(“xxxx”)的GoogleSignInoptions.Builder.这是一个您可以在Firebase身份验证标签下找到的网址 – >登录方法 – > Google – > Web SDK配置 – > Web客户端ID.

requestIdToken Web Client ID

希望这能回答您的疑问.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...