0

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

pl-jay
  • 970
  • 1
  • 16
  • 33
3mr
  • 312
  • 2
  • 16

2 Answers2

1

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

3mr
  • 312
  • 2
  • 16
0

Did you add the sha1 fingerprint from firebase console?

enter image description here

here how get sha1 from keystore (SHA-1 fingerprint of keystore certificate)

her more info about (https://developers.google.com/android/guides/client-auth)

Martin
  • 191
  • 2
  • 5
  • No, I used the the one I got from google cloud api dash board. I am realy stuck in this. I followed the tutorial at https://www.youtube.com/watch?v=w6vhJhv4fps&list=WL&index=3&t=0s . This gives me an error. In fact these seem to use cordova . I want to ue capacitor. Is there a good tuorial/guide line I can use to do this. my requirement is to introduce some form of google login to my ionic application The application is using ionic (angular based not react or other), want to use capacitor to uild the android app as opposed to cordova. Please let me know how I can do or a link – 3mr Jul 31 '20 at 01:51
  • Hi Martin. I now added the finger print. I saw in an article I need to get the web client id from firebase to pass when authenticating from my app. Where can I get this web app id in firebase. Please help. Thanks in advance – 3mr Jul 31 '20 at 06:07
  • you need create it from google developer console https://developers.google.com/adwords/api/docs/guides/authentication#webapp – Martin Jul 31 '20 at 10:58
  • Thanks martin. I had deleted the web app id credential generated by google for my firebase app. Now I deleted all credention on google cloud console and also deleted the web application and the android application on firebase for this project and created both web and android applications anew in firebase. Now I got the web app id automatically created on google cloud dashboard. And I used that web app id to login. Still getting the same error 10. Stuck for days now. ????? – 3mr Jul 31 '20 at 11:05