Want create site? Find Free WordPress Themes and plugins.

1-Installation

You need to install the sdk with npm and configure native Android/iOS project in the react native project.

react-native init ProjectName

2-Install Packages

npm install react-native-google-signin –save

react-native link react-native-google-signin

3-Configure Android Project

First of all register your project on firebase console to get webClient Id and google-services.json. For SHA-1 key open android studio and follow this link. Generate SHA-1 Key

Download and add google-services.json in your project inside android/app like {YourApp}/android/app/google-services.json.

In MainApplication.java file add SDK Packages if already not added during installation,

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
 @Override
 public boolean getUseDeveloperSupport() {
 return BuildConfig.DEBUG;
 }
 @Override
 protected List<ReactPackage> getPackages() {
 return Arrays.<ReactPackage>asList(
 new MainReactPackage(),
 new RNGoogleSigninPackage()
 );
 }
 @Override
 protected String getJSMainModuleName() {
 return "index";
 }
 };
 @Override
 public ReactNativeHost getReactNativeHost() {
 return mReactNativeHost;
 }

Open Gradle.setting file and add

buildscript {
 repositories {
 jcenter()
 maven {
 url 'https://maven.google.com/'
 name 'Google'
 }
 }
}
allprojects {
 repositories {
 .
 .
 .
 maven {
 url 'https://maven.google.com/'
 name 'Google'
 }
 }
}

4-React-Native Code

import React, { Component } from 'react';
import {
 Platform,
 StyleSheet,
 Text,
 TouchableOpacity,
 View
} from 'react-native';
import {GoogleSignin, GoogleSigninButton} from 'react-native-google-signin';
export default class App extends Component<{}> {
 constructor(props) {
 super(props);
 this.state = {
 user: null
 };
 }
 componentDidMount() {
 this._setupGoogleSignin();
 }
 render() {
 if (!this.state.user) {
 return (
 <View style={styles.container}>
 <GoogleSigninButton style={{width: 120, height: 44}} color={GoogleSigninButton.Color.Light} size={GoogleSigninButton.Size.Icon} onPress={() => { this._signIn(); }}/>
 </View>
 );
 }
 if (this.state.user) {
 return (
 <View style={styles.container}>
 <Text style={{fontSize: 18, fontWeight: 'bold', marginBottom: 20}}>Welcome {this.state.user.name}</Text>
 <Text>Your email is: {this.state.user.email}</Text>
 <TouchableOpacity onPress={() => {this._signOut(); }}>
 <View style={{marginTop: 50}}>
 <Text>Log out</Text>
 </View>
 </TouchableOpacity>
 </View>
 );
 }
 }
 async _setupGoogleSignin() {
 try {
 await GoogleSignin.hasPlayServices({ autoResolve: true });
 await GoogleSignin.configure({
 webClientId: '1068112920550-vd21f5li9vnvllh3t7tl5m04unq70e64.apps.googleusercontent.com',
 offlineAccess: false
 });
 const user = await GoogleSignin.currentUserAsync();
 console.log(user);
 this.setState({user});
 }
 catch(err) {
 console.log("Play services error", err.code, err.message);
 }
 }
 _signIn() {
 GoogleSignin.signIn()
 .then((user) => {
 console.log(user);
 this.setState({user: user});
 })
 .catch((err) => {
 console.log('WRONG SIGNIN', err);
 })
 .done();
 }
 _signOut() {
 GoogleSignin.revokeAccess().then(() => GoogleSignin.signOut()).then(() => {
 this.setState({user: null});
 })
 .done();
 }
}
const styles = StyleSheet.create({
 container: {
 flex: 1,
 justifyContent: 'center',
 alignItems: 'center',
 backgroundColor: '#F5FCFF',
 },
});

Here is reference code github Repo

Did you find apk for android? You can find new Free Android Games and apps.