'React-native google signin gives Developer Error
I am trying Google login using React-native-google-signin plugin but it gives me a Developer_Error.I have done exctly same as mention in its document.here is my code ans steps.
1.Installed react-native-google-signin plugin using npm i react-native-google-signin. 2.Then have linked it with react-native link react-native-google-signin 3.After that i did setup of build.gradle file as they mention it in the documents.
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.Updated 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.Then generate SHA1 key using android studion debug.keystore and generate google-services.json file in firebase.
6.Then setting up login.js page like this.
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,
});
}
}
}
These are my details so please someone help me on this i cannot find the appropriate solution online.and yes my SHA1 and clientID is correct i have cheked it already.
Solution 1:[1]
I had this problem too and trawled through many answers saying check your client Id and key hash, both of which I was positive were right.
The thing that got it working for me was I opened OAuth identities in the project management console (not Firebase) at https://console.cloud.google.com/apis/credentials and added an Android Oauth client Id with the correct signature (I did not have one of these there prior for some reason). Redownload the GoogleServices json file.
I also needed to set the webClientId to the "client_type": 3 Oauth client ID. It then worked.
Solution 2:[2]
I was trying keytool -exportcert -keystore ~/.android/debug.keystore -list -v
which of course was giving me a SHA1 key but it was not working, after searching for a while I also look closer into my project/android/app
folder and found that there is a debug.keystore
key too (whose default password is android
, in case some need to know ) so I tried cd android
and keytool -exportcert -keystore app/debug.keystore -list -v
command and the key I got, worked really well. I hope it will help.
Solution 3:[3]
Walkthrough for different modes:
Development Firebase
- run
cd android && ./gradlew signingReport
. - Copy the SHA-1 hash and paste it into the firebase console under Android in Project Settings.
- Download the
google-services.json
file from the Firebase settings and paste the file intoandroid/app
- Use the client
client_type: 3
clientId inside the config.
Development non-Firebase
- run
cd android && ./gradlew signingReport
. - Copy the SHA-1 hash
- Go to Google Cloud Platform Console and click
Create Credentials
->OAuthClientID
. Choose typeAndroid
and paste the hash and fill in the form - Create another Client by clicking
Create Credentials
, but choose typeWeb application
this time. - Use the webclient in your code
Production/Release version
- Go to the Google Play console and copy SHA-1 key from
Release -> Setup -> App Integrity
- Go to Google Cloud Platform Console and click
Create Credentials
->OAuthClientID
. Choose typeAndroid
and paste the hash and fill in the form - Create another Client by clicking
Create Credentials
, but choose typeWeb application
this time. - Use the webclient in your code
Solution 4:[4]
For React native projects:
There are many items in the checklist to get rid of DEVELOPER_ERROR. There seems to be lot of confusion around where the SHA-1 key needs to be set.
Once you have created android client_id in Google developer console you have an option to set SHA-1 key and package name.
You can get the package name from AndroidManifest.xml (projPath/android/app/src/main/AndroidManifest.xml)
and set it in the text box in google developer console(very important to check for typos).
Then fetch your SHA-1 key from debug.keystore using following command for which password is "android"
First figure out location of keystore:
Your app may be either picking from
`pathToReactNativeProj/projName/android/app/debug.keystore`
or: ~/.android/debug.keystore
Then fetch your SHA-1 key from debug.keystore using following command for which password is android
keytool -exportcert -alias androiddebugkey -keystore pathToKeyStore -list -v
copy paste the SHA-1 key generated . This should solve the issue.
Code looks like following:
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");
}
}
Confusion around firebase SHA-1 key:
Setting this key is not required for fetching user info from google. Unless you are using firebase to store your users data you fetched from google you need not worry about it.
Solution 5:[5]
It's just because of your androidClientId
is a mismatch as your google console project
create your new auth client id from your project API console : https://console.developers.google.com/apis/credentials
update configuration to:
myfile.js
like:
GoogleSignin.configure({ androidClientId:'YOUR CLIENT ID' )}
Solution 6:[6]
In my case, my SHA-1 key that I added to firebase project is invalid because I got it from /Users/apple/.android/debug.keystore
.
The correct SHA-1 should be in the android folder inside the Project example: /Users/apple/Documents/Project/testGoogleFirebaseLogin/android/app/debug.keystore
(testGoogleFirebaseLogin is my project folder name)
So, the most convenient way is cd android && ./gradlew signingReport
. It will generate many many lines of data, scroll down and look for SHA-1 from the one that has Store: (your project path)
NOTE: Not the one that has Store: /Users/apple/.android/debug.keystore
.
(Apologize to my English skill, I will be appreciated if some one correct my gramma and make this answer is easier to read)
Solution 7:[7]
For those who are still looking for solutions:
Please match your key fingerprint in firebase console.
Do not initialize the configuration with keys, I repeat, do not provide any configuration object in the .configure() function Do this
GoogleSignIn.configure()
.Point 2 will resolve the issue. :)
Solution 8:[8]
the issus for me was, using the webClientID, without the androidClientID.
webClientID: in google-services.json => "client_type": 3
androidClientID: in google-services.json => "client_type": 1 Then in your file js:
GoogleSignin.configure({ androidClientId: "something.apps.googleusercontent.com", webClientId: "something.apps.googleusercontent.com", });
Solution 9:[9]
In react native theres 2 types of keystores:
- debug.keystore: just for debuging.
- yourownkeystore.keystore: this one is for production. and you need to create it. check this link to know how: https://reactnative.dev/docs/signed-apk-android
while in production. while creating yourownkeystore.keystore. you ll get a specific SHA-1 that will be used for production. take that one for yourownkeystore.keystore and replace it in the firebase console of your project. then redownload the google-services.json file and replace it in your android/app. then get the clientID and the androidID from that json file and place them in the configuration of your google Signing method in js.
Solution 10:[10]
I think sometime it may possible for an old fingerprint (from a different dev in a former time) could be conflicting. So SHA1 should be proper. Delete the old SHA-1 and re-download google-services.json
Solution 11:[11]
Folks who use Firebase for Google Sign in
I am posting this answer because I did try a lot of methods and only this was working fine for me. The issue is happening because, in the RN version 0.61, a new debug.keystore
was introduced. Due to this, the existing/new projects are affected.
To solve this,
- Generate a new android debug key under
android/app
folder. Go to the root folder of your react native app and run the below command.
keytool -list -v -keystore ./android/app/debug.keystore -alias androiddebugkey -storepass android -keypass android
Once the above command ran, it will show the SHA1
in the terminal. Copy it.
- Go to your project
firebase.console
and under yourGeneral
tab in theproject settings
, paste the copiedSHA1
and save it.
Done. Now run the app and it should work fine.
For more info, https://github.com/react-native-google-signin/google-signin/issues/823
Solution 12:[12]
Check you're added the debug and release fingerprints in firebase project settings
Other wise create the debug & release key fingerprints by using the app/build.gradle -> signingConfigs -> debug
$ 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
then copy the sha1/sha256 fingerprints and add it to the project settings -> firebase
Solution 13:[13]
Solution 14:[14]
Add SHA1 key value to the google-services.json file. For that open the google-services.json file in any text editor and add
"certificate_hash": "5e8f16062ea3cd2c4a0d547876baa6f38cabf625"
with your hash value without a colon (:) in android_client_info
Demo google-services.json file
{
"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"
}
or add SHA1 key in the (firebase console) app settings and download the updated google-services.json file.
Then change the GoogleSignIn.configure() method parameter as empty. This is the most important step.
Solution 15:[15]
I also got stuck in this situation when i was publishing my first app. React Native documentation tells about generating a keystore. But as i was using firebase for google auth, it needs sha of that keystore to be mentioned in project settings.
To get the SHA1 from the generated keystore, run these commands :
cd android
cd app
keytool -list -v -keystore {keystore-name}.keystore -alias {alias-name}
Now it will ask for password. enter the password you created while generating the keystore. It will print all details & here you can find the SHA1. Copy the SHA1 fingerprint & add in your firebase console > project settings > android app
Solution 16:[16]
try these, don't use webClientId and offlineAccess: true
GoogleSignin.configure({
ClientId:
'48774575517-o9j0crni6shsal3jnoerm1o19pdqkg05.apps.googleusercontent.com',
});
it's helped me and I don't use firebase,googlePlayServicesAuthVersion = "15.0.1",classpath 'com.google.gms:google-services:3.2.1',nothing
just I install
- npm i @react-native-google-signin/google-signin
- cd android and gradlew clean
Now run the app and it should work fine.
Solution 17:[17]
What happened with me can be extremely rare but still posting here incase someone face it too because I spent a whole day in this. So for me my SHA1 keys were also fine on both google cloud locally and firebase everything was perfect still it was only working on debug build and on release builds I was getting a DEVELOPER ERROR.
after spending lot of time we got to know that whatever we were changing was not getting included in the release build instead we were getting a cached version every time. and finally we get it solved by clearing the cache by doing this .
Solution 18:[18]
I had this error appearing after I upload the app to the play store and after a week of hitting my head here and there. I found that Google has launched a new signings service where they sign your app on the play store after you upload, with their key after which they give you SHA1 for the same on the play store developer console.
under > Release Management > App Signing
take SHA-1 from there and add it to your Firebase project app. And yay! it worked for me and hopefully will work for you if you are facing the same issue.
Solution 19:[19]
works for me:
keytool -list -v -keystore app/debug.keystore
get SHA1 and add in console of firebase
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow