36

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.

Aniruddh Thakor
  • 1,396
  • 2
  • 9
  • 18

24 Answers24

44

Walkthrough for different modes:

Development Firebase

  1. run cd android && ./gradlew signingReport.
  2. Copy the SHA-1 hash and paste it into the firebase console under Android in Project Settings.
  3. Download the google-services.json file from the Firebase settings and paste the file into android/app
  4. Use the client client_type: 3 clientId inside the config.

Development non-Firebase

  1. run cd android && ./gradlew signingReport.
  2. Copy the SHA-1 hash
  3. Go to Google Cloud Platform Console and click Create Credentials -> OAuthClientID. Choose type Android and paste the hash and fill in the form
  4. Create another Client by clicking Create Credentials, but choose type Web application this time.
  5. Use the webclient in your code

Production/Release version

  1. Go to the Google Play console and copy SHA-1 key from Release -> Setup -> App Integrity
  2. Go to Google Cloud Platform Console and click Create Credentials -> OAuthClientID. Choose type Android and paste the hash and fill in the form
  3. Create another Client by clicking Create Credentials, but choose type Web application this time.
  4. Use the webclient in your code
Jeroen van Dijk
  • 459
  • 1
  • 4
  • 3
  • 2
    This is the only solution that worked for me. Make sure to follow step 1 under "Production/Release version", I spent an entire weekend trying to figure out why sign-in was failing only when downloading the app from the PlayStore. – glocore Nov 01 '21 at 13:25
  • 3
    This worked!! I have struggled with this issue for quite some time and apparently, I have been using the wrong SHA1. The `./gradlew signingReport` command shows exactly which to use for which build. Thank you! – Pila Jan 08 '22 at 22:10
  • Thanks for taking the time to explain in detail. – Daniel Barde Oct 02 '22 at 09:39
  • Finally worked for me when I used the SHA-1 key from the Upload key certificate instead of the App signing key certificate. Both are found in the Google play console App Integrity section. – David Jan 04 '23 at 00:02
  • What a clear explanation, thank you! – kaxi1993 Apr 12 '23 at 20:28
  • When you add SHA-1 from Firebase Console, the Google Cloud Platform Console A is also added. The method above did not work in me after adding Firebase Console, I had to update Google-Services.json file – Ugur Jun 18 '23 at 15:53
  • Resolved the error for me. – Capaj Aug 24 '23 at 11:50
32

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.

Uddesh Jain
  • 1,064
  • 2
  • 15
  • 16
18

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.

user37309
  • 597
  • 5
  • 14
  • 1
    Can you explain; "I also needed to set the webClientId to the "client_type": 3 Oauth client ID. It then worked." ? – ronnyrr Aug 30 '20 at 20:44
  • I am a little unsure this was a while ago, but in my google-services.json file I have an oauth_client where one of the objects contains a "client_type" equal to 3. I am assuming I meant use the "client_id" in that file where the "client_type" === 3 – user37309 Aug 31 '20 at 02:44
  • Hmm okay. Thanks for your reply. I've got it working in develop mode, but it still breaks with the developer error in React Native production build :( – ronnyrr Aug 31 '20 at 11:48
  • @ronnyrr please verify that while creating the signed apk for production you are pointing to the correct keystore location. Default alias and password are: androiddebugkey /android – Swaprks Nov 17 '20 at 07:51
8

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.

Sachin Poreyana
  • 1,947
  • 15
  • 12
  • 1
    `keytool -exportcert -alias androiddebugkey -keystore pathToKeyStore -list -v`, this command gives me error `keytool error: java.lang.Exception: Only one command is allowed: both -exportcert and -list were specified.` so i used without -exportcert `keytool -keystore app/debug.keystore -list -v` – Yuji Dec 08 '20 at 13:51
8

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)

Pranat Pannao
  • 119
  • 3
  • 8
7

For those who are still looking for solutions:

  1. Please match your key fingerprint in firebase console.

  2. Do not initialize the configuration with keys, I repeat, do not provide any configuration object in the .configure() function Do this GoogleSignIn.configure().

  3. Point 2 will resolve the issue. :)

6

It's just because of your androidClientId is a mismatch as your google console project

  1. create your new auth client id from your project API console : https://console.developers.google.com/apis/credentials enter image description here

  2. update configuration to: myfile.js like:

GoogleSignin.configure({ androidClientId:'YOUR CLIENT ID' )} enter image description here

M.Daniyal Aslam
  • 489
  • 6
  • 6
4

works for me:

keytool -list -v -keystore app/debug.keystore

get SHA1 and add in console of firebase

3

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,

  1. 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.

  1. Go to your project firebase.console and under your General tab in the project settings, paste the copied SHA1 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

Dharman
  • 30,962
  • 25
  • 85
  • 135
Arun AK
  • 4,353
  • 2
  • 23
  • 46
3

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",
     });
    
Ahmed Bargady
  • 269
  • 4
  • 6
2

In react native theres 2 types of keystores:

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.

Ahmed Bargady
  • 269
  • 4
  • 6
  • You saved my life. for those using Keystore generate through Android studio **".jks"** you can follow these links [SHA-1 fingerprint of Keystore certificate](https://stackoverflow.com/a/15727931) to generate your SHA1. Thanks again – Micessien Oct 07 '21 at 14:28
1

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

sagarchavan
  • 187
  • 3
  • 14
1

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

Karthikeyan Ganesan
  • 1,901
  • 20
  • 23
1

To resolve this issue you must install @react-native-google-signin/google-signin

and follow this:

enter image description here

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Nejib Afdhal
  • 51
  • 1
  • 9
0

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.

Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
0

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

Arun Gupta
  • 133
  • 1
  • 6
0

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

  1. npm i @react-native-google-signin/google-signin
  2. cd android and gradlew clean

Now run the app and it should work fine.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Deepak Singh
  • 749
  • 4
  • 16
0

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 .

Omer Khan
  • 437
  • 2
  • 8
0

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.

0

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.

Preetika
  • 702
  • 8
  • 21
0

In my case, I was calling for idToken by having webClientId and offlineAccess as true. Turns out my webClientId value was not correct. I set its value from google-services.json obtained from firebase console with client_id value from client_type 3.

Be Wake Pandey
  • 491
  • 1
  • 5
  • 14
0

Step 1:

Create release keystore by following methods given in react native official website https://reactnative.dev/docs/signed-apk-android

Step 2:

generate debug SHA1 key by using given command line:

cd android
./gradlew signingReport

Step 3:

Copy and paste SHA1 project section enter image description here

Step 4:

generate release (Important) SHA1 key by using given command line (give full path of your debug keystore file):

keytool -keystore "E:\<You Project folder name>\android\app\my-upload-key.keystore" -list -v

add to firebase project section by clicking add fingerprint enter image description here

Step 5:

get your Web client ID from Authentication > Google > Web SDK configuration > Web client ID

enter image description here

and use in your project in GoogleSignIn Configure() like this:

GoogleSignin.configure({
  scopes: [], // what API you want to access on behalf of the user, default is email and profile
  webClientId: '<Paste here Your copied web client ID>', // client ID of type WEB for your server (needed to verify user ID and offline access)
  offlineAccess: true, // if you want to access Google API on behalf of the user FROM YOUR SERVER
  // hostedDomain: '', // specifies a hosted domain restriction
  // forceCodeForRefreshToken: true, // [Android] related to `serverAuthCode`, read the docs link below *.
  // accountName: '', // [Android] specifies an account name on the device that should be used
  // iosClientId: '<FROM DEVELOPER CONSOLE>', // [iOS] if you want to specify the client ID of type iOS (otherwise, it is taken from GoogleService-Info.plist)
  // googleServicePlistPath: '', // [iOS] if you renamed your GoogleService-Info file, new name here, e.g. GoogleService-Info-Staging
  // openIdRealm: '', // [iOS] The OpenID2 realm of the home web server. This allows Google to include the user's OpenID Identifier in the OpenID Connect ID token.
  // profileImageSize: 120, // [iOS] The desired height (and width) of the profile image. Defaults to 120px
});

That's all I hope It will help someone.

0

Hi Please check your WEBCLIENTID ID

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34195363) – Rohit Gupta Apr 17 '23 at 05:16
0

{ "client_id": "xxxxxxxxxxxxx", "client_type": 3 } setting webclientid with client_type 3 resolves issues

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 01 '23 at 21:05