Please see the FAQ at bottom before opening new issues
You need the following packages
-
Follow this guide to get the configuration file.
-
Place the generated configuration file (
google-services.json) into<YOUR_PROJECT_ROOT>/android/app
-
run
react-native link react-native-google-signin -
In
android/settings.gradleyou should have
...
include ':react-native-google-signin', ':app'
project(':react-native-google-signin').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-signin/android')- Update
android/build.gradlewith
...
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2' // <--- update this
classpath 'com.google.gms:google-services:3.0.0' // <--- add this
}- Update
android/app/build.gradlewith
...
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+"
compile(project(":react-native-google-signin")){
exclude group: "com.google.android.gms" // very important
}
compile 'com.google.android.gms:play-services-auth:9.2.1' // should be at least 9.0.0
}
apply plugin: 'com.google.gms.google-services' // <--- this should be the last line- Register Module (in MainApplication.java)
import co.apptailor.googlesignin.RNGoogleSigninPackage; // <--- import
public class MainApplication extends Application implements ReactApplication {
......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNGoogleSigninPackage() // <-- add this
);
}
......
}- Update gradle wrapper in
android/gradle/wrapper/gradle-wrapper.properties
replace
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
with
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-all.zip
Make sure you have a simulator with Google Play installed.
Also to help with performances, install HAXM from the Android SDK Manager.
Nothing special here, as long as you run your app on a Google Android device (again with play store installed !)
A. My project includes other react-native plugins which have different google play services versions. What to do ??
in android/app/build.gradle exclude google play services from the plugins you use. Like this:
compile(project(":PLUGIN_NAME")){
exclude group: "com.google.android.gms"
}
Then include play services version you need (at least 9.0.0 for this plugin (!))
first install the latest version
npm install --save react-native-google-signin
You need to follow this guide again to make sure everything fit together (gradle version, google-services gradle version, etc...)
clean everything to be sure
cd android
./gradlew clean
now react-native run-android
C. After upgrading and thoroughly following the guide the build fail with Missing api_key/current_key object. what to do ?
open android/app/google-services.json and replace "api_key":[] with "api_key":[{ "current_key": "" }]
This is a permission error. Make sure the certificate_hash in android/app/google-services.json matches your certificate.
To get your sha1-hash
keytool -exportcert -keystore ~/.android/debug.keystore -list -v
Also make sure the application id matches the one you enter on the cloud console.
This is configuration mismatch. Make sure that your android/app/google-services.json is correct.
If you're passing webClientId in configuration object to GoogleSignin.configure() make sure it's correct. You can get your webClientId from Google Developer Console. They're listed under "OAuth 2.0 client IDs".
If you're running your app in debug mode and not using webClientId or you're sure it's correct the problem might be signature (SHA-1 or SHA-256) mismatch. You need to add the following to android/app/build.gradle:
signingConfigs {
+ debug {
+ storeFile file(MYAPP_RELEASE_STORE_FILE)
+ storePassword MYAPP_RELEASE_STORE_PASSWORD
+ keyAlias MYAPP_RELEASE_KEY_ALIAS
+ keyPassword MYAPP_RELEASE_KEY_PASSWORD
+ }
release {
...
}
}Read this medium article. Basically, if you have other play services libraries installed, you have to exclude some dependencies.
