Google Connexion on Android
Introduction
Section titled “Introduction”In this Guide, you will learn how to Configuration Google Connexion with Capgo Social Connexion for Android. I assume that you have already read the general Configuration Guide.
Using Google Connexion on Android
Section titled “Using Google Connexion on Android”In this part, you will learn how to Configuration Google Connexion in Android.
The Android SHA1 certificate is beyond painful and I wouldn’t wish it on anyone to have to set this up. The following steps assume the simplest scenario of an Application that isn’t published to Google Play Store and that is only used by the local simulator, or Développement hardware Appareil.
If you have deployed your app to Google Play Store, you MUST add an additional Android client ID that contains the SHA1 from Google Play console for production releases. You can find the SHA1 hash that Google Play uses to sign your release bundle under Test and release > Setup > App Signing.
Finally, it’s Important to mention that if you mess up, the Erreur will NOT be obvious. It may be very difficult to Débogage. If you struggle with the Configuration, please look at the Github issues.
Additionally, you may look at the Dépannage section of the Google Connexion Configuration for Android for more Information.
You may Créer multiple Android client IDs. This is required if you have multiple SHA1 certificates.
-
Créer an Android client ID.
-
Click on the Recherche bar

-
Search for
credentialsand click on theAPIs and Servicesone (number 2 on the screenshot)
-
Click on the
create credentials
-
Select
OAuth client ID
-
Select the
Androidapplication type
-
Open Android Studio
-
At the very bottom of the navigator, find the
Gradle Scripts
-
Find
build.gradlefor the moduleapp
-
Copy the
android.defaultConfig.applicationId. This will be yourpackage namein the Google console
-
Now, open the terminal. Make sure that you are in the
androidfolder of your app and run./gradlew signInReport

- Scroll to the top of this command. You should see the following. Copy the
SHA1.

- Now, go back to the Google Console. Enter your
applicationIdas thePackage Nameand your SHA1 in the certificate field and clickcreate

-
-
Créer a web client (this is required for Android)
-
Go to the
Create credentialspage in Google Console -
Set application type to
Web
-
Click
Create
-
Copy the client ID, you’ll use this as the
webClientIdin your JS/TS code
-
-
Modify your
MainActivity-
Please open your app in Android Studio. You can run
cap open android -
Find
MainActivity.java-
Open the
appfolder
-
Find
java
-
Find your
MainActivity.javaand click on it
-
-
Modify
MainActivity.java. Please add the following codeimport ee.forgr.capacitor.social.login.GoogleProvider;import ee.forgr.capacitor.social.login.SocialLoginPlugin;import ee.forgr.capacitor.social.login.ModifiedMainActivityForSocialLoginPlugin;import com.getcapacitor.PluginHandle;import com.getcapacitor.Plugin;import android.content.Intent;import android.util.Log;import com.getcapacitor.BridgeActivity;// ModifiedMainActivityForSocialLoginPlugin is VERY VERY important !!!!!!public class MainActivity extends BridgeActivity implements ModifiedMainActivityForSocialLoginPlugin {@Overridepublic void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);if (requestCode >= GoogleProvider.REQUEST_AUTHORIZE_GOOGLE_MIN && requestCode < GoogleProvider.REQUEST_AUTHORIZE_GOOGLE_MAX) {PluginHandle pluginHandle = getBridge().getPlugin("SocialLogin");if (pluginHandle == null) {Log.i("Google Activity Result", "SocialLogin login handle is null");return;}Plugin plugin = pluginHandle.getInstance();if (!(plugin instanceof SocialLoginPlugin)) {Log.i("Google Activity Result", "SocialLogin plugin instance is not SocialLoginPlugin");return;}((SocialLoginPlugin) plugin).handleGoogleLoginIntent(requestCode, data);}}// This function will never be called, leave it empty@Overridepublic void IHaveModifiedTheMainActivityForTheUseWithSocialLoginPlugin() {}} -
Enregistrer the file
-
-
Use Google Connexion in your Application
-
First, import
SocialLoginimport { SocialLogin } from '@capgo/capacitor-social-login'; -
Call Initialiser. This should be called only once.
// onMounted is Vue specific// webClientId is the client ID you got in the web client creation step not the android client ID.onMounted(() => {SocialLogin.initialize({google: {webClientId: '673324426943-avl4v9ubdas7a0u7igf7in03pdj1dkmg.apps.googleusercontent.com',}})}) -
Call
SocialLogin.login. Create a button and run the following code on click.const res = await SocialLogin.login({provider: 'google',options: {}})// handle the responseconsole.log(JSON.stringify(res))
-
-
Configure the emulator for Test
-
Go into
Device managerand click the plus button
-
Créer a virtual Appareil

-
Select any device with a
Play Storeicon
As you can see, the
pixel 8supports thePlay Storeservices -
Click
next
-
Make sure that the OS image is of type
Google Play. IT MUST be of typeGoogle Play
-
Click Suivant

-
Confirm your Appareil. You can name your emulator as you prefer

-
Go into
Device Managerand boot up your simulator
-
After the simulator boots up, go into its Paramètres

-
Go into
Google Play

- Click
Updateand wait about 60 seconds

-
-
Test your Application
If you did everything correctly, you should see the Google Connexion flow working properly:

Dépannage
Section titled “Dépannage”If you have any issues, please look at the Github issues.
The issues with Google Connexion are ALWAYS related to the SHA1 certificate.
If you cannot get the Développement SHA1 certificate, try to use a custom keystore. Here is a comment explaining how to Ajouter keystore to your project.