Android React native google signin给开发者错误

Android React native google signin给开发者错误,android,reactjs,react-native,Android,Reactjs,React Native,我正在尝试使用插件登录Google,但它给了我一个开发者错误。我做的和文档中提到的完全一样。下面是我的代码和步骤 1.使用npm i react native google signin安装react native google signin插件。 2.然后将其与react native link react native google signin链接 3.在那之后,我设置了build.gradle文件,正如他们在文档中提到的那样 ext { buildToolsVer

我正在尝试使用插件登录Google,但它给了我一个开发者错误。我做的和文档中提到的完全一样。下面是我的代码和步骤

1.使用npm i react native google signin安装react native google signin插件。 2.然后将其与react native link react native google signin链接 3.在那之后,我设置了build.gradle文件,正如他们在文档中提到的那样

    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
        googlePlayServicesAuthVersion = "15.0.1"
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2' 
        classpath 'com.google.gms:google-services:3.2.1' 
    }
    allprojects {
        repositories {
                mavenLocal()
                google() 
                maven {url "https://maven.google.com"}
                jcenter()
                maven {
                // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
                url "$rootDir/../node_modules/react-native/android"
                }
                maven {
                    url 'https://maven.google.com/'
                    name 'Google'
                }
        }
    }
4.更新了android/app/build.gradle

    dependencies {

        implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
        implementation project(':react-native-fbsdk')
        compile project(':react-native-vector-icons')
        compile project(':react-native-fused-location')
        compile project(':react-native-fs')
        compile project(':react-native-image-resizer')
        compile project(':react-native-geocoder')
        compile project(':react-native-device-info')
        compile project(':react-native-image-picker')
        compile fileTree(dir: "libs", include: ["*.jar"])
        compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
        compile "com.facebook.react:react-native:+"  // From node_modules
        implementation project(":react-native-google-signin")
        compile (project(':react-native-maps')){
            exclude group: "com.google.android.gms" 
        }
        implementation 'com.google.android.gms:play-services-auth:15.0.1'
        implementation 'com.google.android.gms:play-services-maps:15.0.1'
        implementation 'com.google.android.gms:play-services-location:15.0.1'
        implementation 'com.google.android.gms:play-services-base:15.0.1' 

    }

    task copyDownloadableDepsToLibs(type: Copy) {
        from configurations.compile
        into 'libs'
    }
    apply plugin: 'com.google.gms.google-services' 
5.然后使用android studion debug.keystore生成SHA1密钥,并在firebase中生成google-services.json文件

6.然后像这样设置login.js页面

    async componentDidMount() {
        this._configureGoogleSignIn();

    }
    _configureGoogleSignIn() {
        GoogleSignin.configure({
            webClientId: '775060548127-5nfj43q15l75va9pfav2jettkha7hm2a.apps.googleusercontent.com',// my clientID
            offlineAccess: false
        });
    }
    async GoogleSignin() {
    try {
        await GoogleSignin.hasPlayServices();
        const userInfo = await GoogleSignin.signIn();
        // this.setState({ userInfo, error: null });
        Alert.alert("success:" + JSON.stringify(userInfo));

    } catch (error) {
        if (error.code === statusCodes.SIGN_IN_CANCELLED) {
            // sign in was cancelled
            Alert.alert('cancelled');
        } else if (error.code === statusCodes.IN_PROGRESS) {
            // operation in progress already
            Alert.alert('in progress');
        } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
            Alert.alert('play services not available or outdated');
        } else {
            Alert.alert('Something went wrong', error.toString());
            this.setState({
                error,
            });
        }
    }
}

这些是我的详细信息,因此请有人帮助我,我无法在线找到合适的解决方案。是的,我的SHA1和clientID是正确的,我已经检查过了。

我也遇到了这个问题,并仔细搜索了许多答案,说检查你的客户Id和密钥哈希,这两项我都是肯定的

我在项目管理控制台(不是Firebase)中打开了OAuth标识,并添加了一个具有正确签名的Android OAuth客户端Id(由于某种原因,我之前没有这些标识)。重新下载GoogleServices json文件


我还需要将webClientId设置为“client_type”:3 Oauth客户端ID。然后它就工作了

这只是因为您的
androidClientId
与您的谷歌控制台项目不匹配

  • 从项目API控制台创建新的身份验证客户端id:

  • 将配置更新为:
    myfile.js
    like:

  • 谷歌签名({ androidClientId:“您的客户ID” )}


    对于React本地项目:

    清单中有许多项目可以消除开发人员错误。在需要设置SHA-1键的位置上似乎有很多困惑

    一旦你在谷歌开发者控制台中创建了android客户端id,你就可以选择设置SHA-1密钥和包名

    您可以从AndroidManifest.xml
    (projPath/android/app/src/main/AndroidManifest.xml)
    获取包名,并在google开发者控制台的文本框中进行设置(检查拼写非常重要)

    然后使用以下密码为“android”的命令从debug.keystore获取SHA-1密钥

    首先确定密钥库的位置:

    您的应用程序可能正在从

         `pathToReactNativeProj/projName/android/app/debug.keystore`
    
    或者:
    ~/.android/debug.keystore

    然后使用以下命令从debug.keystore获取SHA-1密钥,该命令的密码为安卓


    keytool-exportcert-alias androiddebugkey-keystore-path-tokeystore-list-v

    复制粘贴生成的SHA-1密钥。这应该可以解决问题

    代码如下所示:

    try {
          GoogleSignin.configure(
          {
            //webClientId is required if you need offline access
            offlineAccess: true,
            webClientId:'2423432-43234234232432423234.apps.googleusercontent.com',
            androidClientId: '3242343242322432-2342323432232324343323.apps.googleusercontent.com',
            scopes: ['profile', 'email']
          });
          await GoogleSignin.hasPlayServices();
          console.log("reached google sign in");
          const userInfo = await GoogleSignin.signIn();
          console.log(userInfo);
          this.setState({ userInfo });
        } catch (error) {
          if (error.code === statusCodes.SIGN_IN_CANCELLED) {
            console.log("error occured SIGN_IN_CANCELLED");
            // user cancelled the login flow
          } else if (error.code === statusCodes.IN_PROGRESS) {
            console.log("error occured IN_PROGRESS");
            // operation (f.e. sign in) is in progress already
          } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
            console.log("error occured PLAY_SERVICES_NOT_AVAILABLE");
          } else {
            console.log(error)
            console.log("error occured unknow error");
          }
        }
    
    围绕firebase SHA-1键的混淆:


    从google获取用户信息不需要设置此键。除非您使用firebase存储您从google获取的用户数据,否则您无需担心。

    我认为有时旧指纹(以前来自不同的开发人员)可能会发生冲突。所以SHA1应该是合适的。删除旧的SHA-1并重新下载google服务。json

    我正在尝试keytool
    -exportcert-keystore~/.android/debug.keystore-list-v
    ,这当然给了我一个SHA1密钥,但它不起作用,搜索了一段时间后,我也仔细查看了我的
    project/android/app
    文件夹,发现还有一个
    debug.keystore
    密钥(默认密码为
    android
    ,以防有人需要知道)所以我尝试了
    cd-android
    keytool-exportcert-keystore-app/debug.keystore-list-v
    命令,我得到的密钥运行得非常好。我希望它能有所帮助。

    就我而言,我添加到firebase项目中的SHA-1密钥无效,因为我是从
    /Users/apple/.android/debug.keystore
    获得的

    正确的SHA-1应该在项目示例中的android文件夹中:
    /Users/apple/Documents/Project/testGoogleFirebaseLogin/android/app/debug.keystore
    (testGoogleFirebaseLogin是我的项目文件夹名称)

    因此,最方便的方法是
    cd-android&./gradlew-signingReport
    。它将生成许多行数据,向下滚动并从具有
    Store:(您的项目路径)

    注意:不是具有
    Store:/Users/apple/.android/debug.keystore


    (对我的英语水平表示歉意,如果有人纠正我的语法,并使此答案更易于阅读,我将不胜感激)

    对于那些仍在寻找解决方案的人:

  • 请在firebase控制台中匹配您的密钥指纹

  • 不要用键初始化配置,我重复一遍,不要在.configure()函数中提供任何配置对象 执行此操作
    GoogleSignIn.configure()

  • 第2点将解决问题。:)


  • 将SHA1键值添加到google-services.json文件。为此,请打开google-services.json 在任何文本编辑器中创建文件并添加

    “证书散列”:“5e8f16062ea3cd2c4a0d547876baa6f38cabf625”

    android\u client\u info

    演示google-services.json文件

    {
      "project_info": {
        "project_number": "108005055433",
        "firebase_url": "https://se-ai-camera.firebaseio.com",
        "project_id": "demo-app",
        "storage_bucket": "demo-app.appspot.com"
      },
      "client": [
        {
          "client_info": {
            "mobilesdk_app_id": "1:108005055433:android:323bf88853cd2899872618",
            "android_client_info": {
              "package_name": "com.myapp",
              "certificate_hash": "5e8f16062ea3cd2c4a0d547876baa6f38cabf625"
            }
          },
          "oauth_client": [
            {
              "client_id": "108005055433-q748qmcrn9a3j4qmg9srrkbotvr4emh1.apps.googleusercontent.com",
              "client_type": 3
            }
          ],
          "api_key": [
            {
              "current_key": "AIzaSyAuGCMQoW0tM7QMhpAgMIi0sK3vj0Nj8lk"
            }
          ],
          "services": {
            "appinvite_service": {
              "other_platform_oauth_client": [
                {
                  "client_id": "108005055433-q748qmcrn9a3j4qmg9srrkbotvr4emh1.apps.googleusercontent.com",
                  "client_type": 3
                }
              ]
            }
          }
        }
      ],
      "configuration_version": "1"
    }
    
    或者在()应用程序设置中添加SHA1密钥,并下载更新的google-services.json文件


    然后将GoogleSignIn.configure()方法参数更改为空。这是最重要的步骤。

    不同模式的演练:

    发展火基
  • 运行cd android&&./gradlew签名报告
  • 复制SHA-1散列并将其粘贴到项目设置中Android下的firebase控制台中
  • 从Firebase设置下载
    google services.json
    文件,并将该文件粘贴到
    android/app
  • 使用客户端
    客户端类型:3cd android
    cd app
    
    keytool -list -v -keystore {keystore-name}.keystore -alias {alias-name}
    
    $ keytool -list -v -keystore android/app/debug.keystore -alias androiddebugkey -storepass android -keypass android
    
    
    $ keytool -list -v -keystore android/app/release.keystore -alias androidrelease-aliaskey -storepass android -keypass android