Banging your head against the wall trying to ad Sign in with Google to your React Native application? If the error message you keep running into happens to be DEVELOPER_ERROR, I think I have your fix.
For me, the problem was my build.gradle file for my React Native Android app. The app I happen to be working on has already been published on the Google Play Store, so the production version of the app has been signed using a release version keystore. Apparently I deleted the configuration for the debug version of the app, which did not cause me any problems other than breaking Sign in with Google.
Writing about obscure app configurations can be tough. Does any of what I wrote above make any sense? Probably not! So to make things a little clearer here is what my build.gradle file looked like that did NOT work with Google Social Login:
And here is the corrected build.gradle file that works with Google Social Login:
I’m sure there are a million different ways you can screw up implementing Sign in with Google, however, if you were able to get Google Social Login to work in a test app, but are having trouble getting it to work in your production app, then this might be your problem.
Also, you need to make sure that you have registered a development and production version of your app in the Google Developer Console. For example, let’s pretend you only have one app registered and it’s working great during development. Then you try to use Sign in with Google in the release version of your app. If you’ve only registered the debug version of your app in the console, Google Social Login isn’t going to work in the release version of your app. So, make sure you register a debug version of your app in the Google Developer Console, and then create a second release version of your app in the Google Developer Console as well. You can pretty much use all of the same code in your app, you will just need to write some logic to toggle between the two different clientIds depending on whether you are running the debug version of your app or the release version of your app.
I know that isn’t very intuitive, or self explanatory, so I’ll clarify: You have to register 2 different applications in the Google Developer Console. While you are developing your app you only need one. But after you go to publish the production version of your app, you will need to register it as a completely different app. Doesn’t make much sense does it? But that’s the way it is!
Last, this blog post really only deals with a rare edge case involving build.gradle. So if you do not find this particular post helpful please follow along with the official react-native-community/google-signin or expo-google-sign-in docs. However, this problem was quite a doozy for me! So hopefully this post will end up helping someone out there.