反应原生谷歌登录api无法正常工作

时间:2016-07-02 08:37:47

标签: android api react-native google-signin

单击GoogleSigninButton组件时,我的_signIn()函数无法正常工作。我希望点击按钮时弹出谷歌凭证屏幕

这是我的index.android.js

public void onClick(View v) {
    try {
        if (player != null) {
            player.stop();
            player.release();
        }
    } catch (Exception e) {
    }
    player = MediaPlayer.create(activityContext, soundId);
    player.start();
}

build.gradle文件

    import {GoogleSignin, GoogleSigninButton} from 'react-native-google-signin';

class xyz extends Component {
  _signIn () {
    GoogleSignin.signIn()
.then((user) => {
  console.log(user);
  this.setState({user: user});
})
.catch((err) => {
  console.log('WRONG SIGNIN', err);
})
.done();
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit index.android.js
        </Text>
        <Text style={styles.instructions}>
          Shake or press menu button for dev menu
        </Text>
        <GoogleSigninButton
    style={{width: 48, height: 48}}
    size={GoogleSigninButton.Size.Icon}
    color={GoogleSigninButton.Color.Dark}
    onPress={this._signIn.bind(this)}/>
      </View>
    );
  }
}

settings.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
        classpath 'com.google.gms:google-services:2.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

应用程序/的build.gradle

rootProject.name = 'xyz'

include ':app'
include ':react-native-google-signin', ':app'
project(':react-native-google-signin').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-signin/android')

3 个答案:

答案 0 :(得分:1)

尝试获取你的sha1:

keytool -exportcert -keystore ~/.android/debug.keystore -list -v

然后转到您的google api控制台,确保在Android客户端上为com.yourproject注册了正确的sha1。不知何故keytool可能会被更改(我不确定可能是由于升级sdk buid工具等),你需要在google api控制台上匹配它。这对我有用。

答案 1 :(得分:0)

首先尝试拨打GoogleSignin.configure({YOUR_CONFIG_DATA}) configure 方法会创建新的_apiClient对象,该对象在 signIn 方法中使用。 (在android/src/main/java/co/apptailor/googlesignin/RNGoogleSigninModule.java

答案 2 :(得分:0)

Google已在Play商店中发布了一项新的签名服务。在发布控制台中,Google会使用其密钥库对您的应用进行签名。签名后,它将为您提供一个新的SHA,您必须在您的Firebase帐户中添加它。看到图片以获得更好的理解

image showing where to update app signing