android - React-native google signin 给出开发者错误

标签 android reactjs react-native

我正在尝试使用 React-native-google-signin 登录 Google插件,但它给了我一个 Developer_Error。我完全按照它的文档中提到的那样做了。这是我的代码和步骤。

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 key ,并在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 是正确的,我已经检查过了。

最佳答案

不同模式的演练:

开发 Firebase

  1. 运行 cd android && ./gradlew signingReport
  2. 复制 SHA-1 哈希并将其粘贴到项目设置中 Android 下的 firebase 控制台中。
  3. 从 Firebase 设置下载 google-services.json 文件并将文件粘贴到 android/app
  4. 在配置中使用客户端 client_type: 3 clientId。

非 Firebase 开发

  1. 运行 cd android && ./gradlew signingReport
  2. 复制 SHA-1 哈希
  3. 转到 Google Cloud Platform Console然后点击 Create Credentials -> OAuthClientID。选择类型 Android 并粘贴哈希并填写表格
  4. 通过单击 Create Credentials 创建另一个客户端,但这次选择类型 Web application
  5. 在您的代码中使用网络客户端

生产/发布版本

  1. 转到 Google Play 控制台并从 Release -> Setup -> App Integrity 复制 SHA-1 key
  2. 转到 Google Cloud Platform Console然后点击 Create Credentials -> OAuthClientID。选择类型 Android 并粘贴哈希并填写表格
  3. 通过单击 Create Credentials 创建另一个客户端,但这次选择类型 Web application
  4. 在您的代码中使用网络客户端

关于android - React-native google signin 给出开发者错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54417232/

相关文章:

android - Firebase Crashlytics 使用 Retrofit 和协程报告 Android 项目上的假崩溃

android - LocationManager.requestLocationUpdates 添加或更新?

android - 应用插件失败 [id 'com.android.internal.version-check' ]

android - 在Android Studio中找不到名称为 'debug'的配置

reactjs - 从外部调用 React 组件方法

javascript - Github 用户查找器 api,如何每次搜索返回多个用户? JS

reactjs - 在 react 中显示 Flash 消息

ios - 为什么我不能在 iOS 上离开键盘以在 React Native App 中发送 Post?

reactjs - 无效的钩子(Hook)调用 React

react-native - 如何在 native 天才聊天中显示与我聊天的人的姓名