google sign in does not work on ionic android mobile application generated using capacitor – exception thrown as 10

Issue

I am developing an ionic app for android and generating it using capacitor. I want to introduce google login to my app. I am getting err 10 when I try to login. Created a client id for android for the keys tore being used to sign the app. The code is as below

import '@codetrix-studio/capacitor-google-auth';
import { AngularFireAuth } from '@angular/fire/auth';
import { AngularFirestore } from '@angular/fire/firestore';
import { Router } from '@angular/router';
import { Subject, ReplaySubject } from 'rxjs';
import { GooglePlus } from '@ionic-native/google-plus/ngx';
import * as firebase from 'firebase';
import { Plugins } from '@capacitor/core';
import { FirebaseApp } from '@angular/fire';
import { Platform } from '@ionic/angular';

signInWithGoogle(): Promise<void> {

        return new Promise((resolve, reject) > {

            this.TESTSubject.next('calling google.login');
            this.google.login({
                webClientId: '<my-client-id-part-from-oogle-developer-dashboard>.apps.googleusercontent.com',
                offline: true, scopes: 'profile email'
            })
            .then(gplusUser > {
                this.TESTSubject.next('gplus user recieved ' + gplusUser.email);
                return this.afa.signInWithCredential(firebase.auth.GoogleAuthProvider.credential(gplusUser.idToken));
            })
            .then(r > {
                this.TESTSubject.next('firebase loin OK ');
                resolve();
            })
            .catch(err > {
                reject(err);
            });
        });

    }

When I use this on the device I get the exception thrown when calling this.google.login(.... The exception comes as 10

I use the below command to generate the android app using capacitor in my project directory

    ionic build && npx cap sync android && ionic capacitor copy android && cd android && gradlew assembleRelease && cd app/build/outputs/apk/release && jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore online-mkt.keystore app-release-unsigned.apk online-mkt-mobileapps

    zipalign -v 4 app-release-unsigned.apk mobruk-signed.apk

I have been struggling on this for days. Any help is much appreciated.

my ionic info gives the below

    Ionic:

       Ionic CLI                     : 5.4.16 (C:\Users\<myname>\AppData\Roaming\npm\node_modules\ionic)
       Ionic Framework               : @ionic/angular 5.0.7
       @angular-devkit/build-angular : 0.803.26
       @angular-devkit/schematics    : 8.3.26
       @angular/cli                  : 8.3.26
       @ionic/angular-toolkit        : 2.2.0

    Capacitor:

       Capacitor CLI   : 2.2.1
       @capacitor/core : 2.2.1

    Cordova:

       Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
       Cordova Platforms : android 8.1.0
       Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 5 other plugins)

    Utility:

       cordova-res : not installed
       native-run  : not installed

    System:

       Android SDK Tools : 26.1.1 (C:\Users\<myname>\AppData\Local\Android\Sdk)
       NodeJS            : v10.16.0 (C:\Program Files\nodejs\node.exe)
       npm               : 6.13.1
       OS                : Windows 7

Solution

I found the issue. I had my package name specified in configs.xml in my ionic project. But that that was not the one as I expected which was embedded in my apk file. I found it out by running the below command

aapt dump badging my apk file with path

The name of the package there was io.ionic.starter So in my google cloud console I deleted the credential for android type and recreated another credential giving the package name as io.ionic.starter. The exception is no more and it logs in. I am not sure why the package name is not taken from my configs.xml file. I am nt using andoid studio to build the app, I am building the app on command prompt with the below command

ionic build && npx cap sync android && ionic capacitor copy android && cd android && gradlew assembleRelease && cd app/build/outputs/apk/release && jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore online-mkt.keystore app-release-unsigned.apk online-mkt-mobileapps

This might be the reason for the package on configsxml not getting embedded to the apk. Not sure. Hope some one out there can shed some light. Thanks Martin for your time for trying to help me out. Much appreciated. Thanks

Answered By – 3mr

Leave a Comment