首页 文章

Google使用Firebase登录Android - statusCode DEVELOPER_ERROR

提问于
浏览
18

我尝试在我的Firebase连接的Android应用中实施Google登录 . 当我运行应用程序并按下Google登录按钮时 - 没有任何反应 . 我在onActivityResult中收到此错误: Status .

我的代码如下所示:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == REQUEST_CODE_GOOGLE_LOGIN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);

        if (result.isSuccess()){
            GoogleSignInAccount account = result.getSignInAccount();
            String emailAddres = account.getEmail();
            getGoogleQAuthToken(emailAddres);
        }
    }
}

         private void getGoogleQAuthToken(final String emailAddres){
             AsyncTask<Void,Void,String> task = new AsyncTask<Void, Void, String>() {
                 String errorMessage = null;

                 @Override
                 protected String doInBackground(Void... params) {
                     String token = null;
                     try {
                         String scope = "oauth2:profile email";
                         token = GoogleAuthUtil.getToken(MainActivity.this, emailAddres, scope);
                     } catch (IOException transientEx) {

                         errorMessage = "Network error: " + transientEx.getMessage();
                     } catch (UserRecoverableAuthException e) {
                         Intent recover = e.getIntent();
                         startActivityForResult(recover, MainActivity.REQUEST_CODE_GOOGLE_LOGIN);
                     } catch (GoogleAuthException authEx) {
                         errorMessage = "Error authenticating with Google: " + authEx.getMessage();
                     }
                     return token;
                 }

我在app /目录中添加了JSON配置文件并添加了依赖项:

buildscript {
repositories {
    jcenter()
}

dependencies {
    classpath 'com.google.gms:google-services:1.5.0-beta2'
}
     }


     dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.+'
compile 'com.firebase:firebase-client-android:2.3.0+'

/* For Google Play Services */
compile 'com.google.android.gms:play-services-safetynet:8.3.0'
compile 'com.google.android.gms:play-services-auth:8.3.0'
compile 'com.google.android.gms:play-services:8.3.0'

compile('com.afollestad.material-dialogs:core:0.8.3.0@aar') {
    transitive = true
}

/* Firebase UI */
compile 'com.firebaseui:firebase-ui:0.2.2'

compile 'com.android.support:cardview-v7:23.1.+'
compile 'com.android.support:recyclerview-v7:23.1.+'
compile 'com.android.support:design:23.1.+'


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

我正在寻找解决方案时间......请帮助!!

11 回答

  • 5

    DEVELOPER_ERROR 表示Google Play服务无法根据您的SHA1和程序包名称从控制台中找到匹配的客户端 . 您可以在Firebase console的设置页面中为给定的包名添加SHA1,或者通过添加Firebase将新包名添加到您的Android应用按钮 .

    一般来说,有些事情需要检查:

    • 确保您的包裹名称符合您的预期 - 例如它是build.gradle中的一个,并且它没有在构建变体或产品风格中被覆盖 .

    • 确保已在控制台中注册了调试并释放SHA1密钥 .

  • 0

    如果您的应用程序启用了Google Play App Signing,那么它将在发布之前将您的发布签名密钥替换为googles服务器上的密钥 . 您可以从 Google Play Console -> Release Management -> App Signing 检查是否已启用它 .

    在我的情况下,我必须从“应用程序签名证书”部分复制SHA1并将其添加到Firebase项目常规设置部分,重新生成json文件,将其添加到项目并重新上载apk,并且错误已解决 .

  • 1

    Error code 10 is constant value of CommonStatusCodes.DEVELOPER_ERROR which implies you have misconfigured your project

    你可以做什么

    • 检查PlayStore控制台和Firebase控制台中的SHA是否相同 .

    Copy SHA from Google Play console

    enter image description here

    paste it into Firebase Console

    enter image description here

    What else you can do?

    以简单的英语失败显示有意义的消息

    // Google Sign In failed, update UI appropriately
                Log.w(TAG, "Google sign in failed", e);
    
                String messageToDisplay = "Authentication failed.";
                switch (e.getStatusCode()) {
                    case CommonStatusCodes.API_NOT_CONNECTED: //17
                        messageToDisplay += "The client attempted to call a method from an API that failed to connect.";
                        break;
    
                    case CommonStatusCodes.DEVELOPER_ERROR: //10
                        messageToDisplay += "The application is misconfigured.";
                        break;
    
                    case CommonStatusCodes.ERROR: //13
                        messageToDisplay += "The operation failed with no more detailed information.";
                        break;
    
                    case CommonStatusCodes.INTERNAL_ERROR: //8
                        messageToDisplay += "An internal error occurred.";
                        break;
    
                    case CommonStatusCodes.INVALID_ACCOUNT: //8
                        messageToDisplay += "Invalid account name specified.";
                        break;
    
                    case CommonStatusCodes.SIGN_IN_REQUIRED: //8
                        messageToDisplay += "Please Sign In to continue.";
                        break;
                }
    
                Toast.makeText(LoginActivity.this, messageToDisplay,
                        Toast.LENGTH_SHORT).show();
    
  • 7

    我有同样的问题 . 如果您有SHA1调试并释放SHA1,会发生什么 . 通常我们只使用SHA1 Debug并生成.apk签名到google play,但是当我们使用google sigin时你必须输入SHA1的firebase版本 .

    要查看发行版SHA1,请使用以下命令:

    keytool -list -v -keystore C:\ProjectsData\keystore\my-release-key.keystore -alias alias_name
    

    然后在Firebase上输入此SHA1

    https://support.google.com/firebase/answer/7000104

    这个回答SHA1:

    SHA-1 fingerprint of keystore certificate

    希望我能帮助你 .

  • 14

    我使用以下步骤创建了新的调试SHA1密钥,并在项目设置中替换了SHA1密钥 . 它对我有用 .

    • 打开你的项目 .
    • 单击文件菜单 - >新建 - >单击Google - >选择Google Map 活动 - >单击完成 . -Android studio会生成自动google_maps_api.xml文件 .
    • 你可以在这个文件中获得调试SHA1密钥 .

    在项目设置中替换此SHA1密钥,然后从设置中下载新的 google-services.json 并在项目中替换它,因为您的certificate_hash和client_id将更改 .

  • 0

    我有同样的问题,我通过这些步骤得到了它:

    1. Add DEBUG_KEYSTORE SHA1 fingerprint to the firebase project. use the following command(MAC/LINUX)

    keytool -exportcert -list -v \-alias androiddebugkey -keystore ~/.android/debug.keystore
    

    2. Now Generate a signed apk of your project. The process includes generating a keystore for your app's release version. Copy the path of the newly generated .jks file.

    3. Now generate RELEASE_KEYSTORE SHA1 fingerprint using the following command

    keytool -list -v -keystore FULL_PATH_TOJKS_FILE -alias ALIAS_NAME
    

    4. Copy the new SHA1 from the output and add it as another SHA1 fingerprint in your firebase application console.

    现在你很高兴! ----希望!它有助于 .

  • 0

    我认为您需要更改播放服务版本 .

    请参阅Firebase Android CodelabFirebase Auth dependency 添加到您的app / build.gradle文件中 .

    尝试在gradle中更新您的播放服务,如下所示:

    /* For Google Play Services */
    ...
    compile 'com.google.android.gms:play-services:9.0.0'
    ...
    

    DEVELOPER_ERROR

    应用程序配置错误 . 此错误无法恢复,将被视为致命错误 . 开发人员应在此之后查看日志以确定更多可操作的信息 .

  • 1

    在创建OAuth密钥时,您需要确保提供正确的软件包名称 . 这意味着清单文件中包含的包名称 .

    如果您使用多个模块(例如某些库,如FirebaseUI-Android),请确保在创建密钥时使用您从中请求Google身份验证的程序包名称 .

  • -1

    我遇到过同样的问题 . 经过2天的痛苦,我发现我的版本SHA1是incorect(我曾经使用java / bin中的keytool来获取它并且它给了我一个糟糕的SHA1 . 可能是因为现在Android Studio使用自己的java包而不是JDK) . 更好的方法来获取核心SHA1 SHA-1 fingerprint of keystore certificate

  • 0

    点击Here(Google Developer gide line)并为Firebase控制台创建新项目此链接设置为默认设置,因此您无需添加手册

  • 22

    有同样的问题 . 但在我清理并重建项目后工作正常 . :d

相关问题