Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android App Crashing when SIgnIn button is clicked #389

Open
MalikHamza007 opened this issue Aug 10, 2024 · 11 comments
Open

Android App Crashing when SIgnIn button is clicked #389

MalikHamza007 opened this issue Aug 10, 2024 · 11 comments

Comments

@MalikHamza007
Copy link

Ok so I used this pluggin to create a simple google sign in it works best on web and on android the app crashes when signIn function is clicked the app crashes and yes i have checked every thing my credentials client id strings even main java is correct when I debug the app the pluggin also syncs in the catlog. " E Serious error executing plugin" and another error. "E FATAL EXCEPTION: CapacitorPlugins
Process: io.ionic.starter, PID: 2383"

@jhenriquez07
Copy link

jhenriquez07 commented Aug 13, 2024

Hi @MalikHamza007 , Same issue in my code.
Did you find any solution?

erious error executing plugin java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138) at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:816) at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0) at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8) at android.os.Handler.handleCallback(Handler.java:959) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.os.HandlerThread.run(HandlerThread.java:85) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent com.google.android.gms.auth.api.signin.GoogleSignInClient.getSignInIntent()' on a null object reference at com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth.signIn(GoogleAuth.java:81) at java.lang.reflect.Method.invoke(Native Method)  at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)  at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:816)  at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0)  at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8)  at android.os.Handler.handleCallback(Handler.java:959)  at android.os.Handler.dispatchMessage(Handler.java:100)  at android.os.Looper.loopOnce(Looper.java:232)  at android.os.Looper.loop(Looper.java:317)  at android.os.HandlerThread.run(HandlerThread.java:85)  2024-08-13 12:01:30.713 14460-14788 AndroidRuntime io.ionic.eanaquel.qa E FATAL EXCEPTION: CapacitorPlugins Process: io.ionic.eanaquel.qa, PID: 14460 java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:825) at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0) at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8) at android.os.Handler.handleCallback(Handler.java:959) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.os.HandlerThread.run(HandlerThread.java:85) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138) at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:816) at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0)  at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8)  at android.os.Handler.handleCallback(Handler.java:959)  at android.os.Handler.dispatchMessage(Handler.java:100)  at android.os.Looper.loopOnce(Looper.java:232)  at android.os.Looper.loop(Looper.java:317)  at android.os.HandlerThread.run(HandlerThread.java:85)  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent com.google.android.gms.auth.api.signin.GoogleSignInClient.getSignInIntent()' on a null object reference at com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth.signIn(GoogleAuth.java:81) at java.lang.reflect.Method.invoke(Native Method)  at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)  at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:816)  at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0)  at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8)  at android.os.Handler.handleCallback(Handler.java:959)  at android.os.Handler.dispatchMessage(Handler.java:100)  at android.os.Looper.loopOnce(Looper.java:232)  at android.os.Looper.loop(Looper.java:317)  at android.os.HandlerThread.run(HandlerThread.java:85) 

@riderx
Copy link
Contributor

riderx commented Aug 15, 2024

I think it’s due to the last change in v6.
Look if your initialize method send the web client id. If yes remove it on mobile or sent it conditionally with the right one by platform.
Web, iOS or android.
It’s now used in priority

@eqcb
Copy link

eqcb commented Sep 5, 2024

I'm having the same issue.
Was not passing ClientId in the initialize method. Error continues even if I pass it.

Fixed by removing one optional plugin I was trying out 'cordova-plugin-lottie-splashscreen' that added

    implementation "androidx.annotation:annotation:1.5.0"
    implementation "androidx.appcompat:appcompat:1.3.0"

to my capacitor.build.gradle.

not sure what really cause it. no time to look further as I'm sole dev of my app.

Capacitor 6 and 3.4.0-rc.4

Serious error executing plugin java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138) at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:820) at com.getcapacitor.Bridge.$r8$lambda$FNYM7cvgeBk0k8YXQH7M96Mrf-c(Unknown Source:0) at com.getcapacitor.Bridge$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0) at android.os.Handler.handleCallback(Handler.java:958) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:230) at android.os.Looper.loop(Looper.java:319) at android.os.HandlerThread.run(HandlerThread.java:67) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent com.google.android.gms.auth.api.signin.GoogleSignInClient.getSignInIntent()' on a null object reference at com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth.signIn(GoogleAuth.java:81) at java.lang.reflect.Method.invoke(Native Method)  at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)  at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:820)  at com.getcapacitor.Bridge.$r8$lambda$FNYM7cvgeBk0k8YXQH7M96Mrf-c(Unknown Source:0)  at com.getcapacitor.Bridge$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)  at android.os.Handler.handleCallback(Handler.java:958)  at android.os.Handler.dispatchMessage(Handler.java:99)  at android.os.Looper.loopOnce(Looper.java:230)  at android.os.Looper.loop(Looper.java:319)  at android.os.HandlerThread.run(HandlerThread.java:67) 

                                                                     `FATAL EXCEPTION: CapacitorPlugins
                                                                                                Process: xxxx, PID: 5973
                                                                                                java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
                                                                                                	at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:829)
                                                                                                	at com.getcapacitor.Bridge.$r8$lambda$FNYM7cvgeBk0k8YXQH7M96Mrf-c(Unknown Source:0)
                                                                                                	at com.getcapacitor.Bridge$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
                                                                                                	at android.os.Handler.handleCallback(Handler.java:958)
                                                                                                	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                	at android.os.Looper.loopOnce(Looper.java:230)
                                                                                                	at android.os.Looper.loop(Looper.java:319)
                                                                                                	at android.os.HandlerThread.run(HandlerThread.java:67)
                                                                                                Caused by: java.lang.reflect.InvocationTargetException
                                                                                                	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                	at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)
                                                                                                	at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:820)
                                                                                                	at com.getcapacitor.Bridge.$r8$lambda$FNYM7cvgeBk0k8YXQH7M96Mrf-c(Unknown Source:0) 
                                                                                                	at com.getcapacitor.Bridge$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0) 
                                                                                                	at android.os.Handler.handleCallback(Handler.java:958) 
                                                                                                	at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                                                	at android.os.Looper.loopOnce(Looper.java:230) 
                                                                                                	at android.os.Looper.loop(Looper.java:319) 
                                                                                                	at android.os.HandlerThread.run(HandlerThread.java:67) 
                                                                                                Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent com.google.android.gms.auth.api.signin.GoogleSignInClient.getSignInIntent()' on a null object reference
                                                                                                	at com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth.signIn(GoogleAuth.java:81)
                                                                                                	at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                	at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138) 
                                                                                                	at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:820) 
                                                                                                	at com.getcapacitor.Bridge.$r8$lambda$FNYM7cvgeBk0k8YXQH7M96Mrf-c(Unknown Source:0) 
                                                                                                	at com.getcapacitor.Bridge$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0) 
                                                                                                	at android.os.Handler.handleCallback(Handler.java:958) 
                                                                                                	at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                                                	at android.os.Looper.loopOnce(Looper.java:230) 
                                                                                                	at android.os.Looper.loop(Looper.java:319) 
                                                                                                	at android.os.HandlerThread.run(HandlerThread.java:67) `                           	

@sarmate
Copy link

sarmate commented Sep 15, 2024

Same issue. Hope a solution will be find

@riderx
Copy link
Contributor

riderx commented Sep 15, 2024

Please look the new doc it explains clearly the issue, and how to solve it.
I’m creating a fork with Capgo who going to have all social as this is a recurring problem for all social login

@DaveRicho
Copy link

I think it’s due to the last change in v6. Look if your initialize method send the web client id. If yes remove it on mobile or sent it conditionally with the right one by platform. Web, iOS or android. It’s now used in priority

Hi @riderx, is this what you are explaining here (or have I misunderstood)?:

import { Plugins, Capacitor } from '@capacitor/core';
const { GoogleAuth } = Plugins;

async function initializeGoogleAuth() {
  const isAndroid = Capacitor.getPlatform() === 'android';
  const isIOS = Capacitor.getPlatform() === 'ios';
  
  let clientId = '';

  if (isAndroid) {
    // Use the Android client ID for Android devices
    clientId = 'YOUR_ANDROID_CLIENT_ID.apps.googleusercontent.com';
  } else if (isIOS) {
    // Use the iOS client ID for iOS devices
    clientId = 'YOUR_IOS_CLIENT_ID.apps.googleusercontent.com';
  } else {
    // Use the Web client ID for Web platforms
    clientId = 'YOUR_WEB_CLIENT_ID.apps.googleusercontent.com';
  }

  try {
    await GoogleAuth.initialize({
      clientId: clientId,
      // grantOfflineAccess: true,
      scopes: ['profile', 'email']
    });

    console.log('GoogleAuth initialized successfully');
  } catch (error) {
    console.error('Error initializing GoogleAuth:', error);
  }
}

Thanks,
Dave.

@riderx
Copy link
Contributor

riderx commented Sep 29, 2024

Yes correct.
But to be fair, social login are messy for a long time in Capacitor. So I'm finishing up a plugin to have Google, Apple, Facebook in one plugin and with a simple configuration, and good Doc.
The code is done here: https://github.com/Cap-go/capacitor-social-login
We are finishing up the doc this week.

@MalikHamza007
Copy link
Author

Hi @MalikHamza007 , Same issue in my code. Did you find any solution?

erious error executing plugin java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138) at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:816) at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0) at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8) at android.os.Handler.handleCallback(Handler.java:959) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.os.HandlerThread.run(HandlerThread.java:85) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent com.google.android.gms.auth.api.signin.GoogleSignInClient.getSignInIntent()' on a null object reference at com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth.signIn(GoogleAuth.java:81) at java.lang.reflect.Method.invoke(Native Method)  at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)  at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:816)  at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0)  at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8)  at android.os.Handler.handleCallback(Handler.java:959)  at android.os.Handler.dispatchMessage(Handler.java:100)  at android.os.Looper.loopOnce(Looper.java:232)  at android.os.Looper.loop(Looper.java:317)  at android.os.HandlerThread.run(HandlerThread.java:85)  2024-08-13 12:01:30.713 14460-14788 AndroidRuntime io.ionic.eanaquel.qa E FATAL EXCEPTION: CapacitorPlugins Process: io.ionic.eanaquel.qa, PID: 14460 java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:825) at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0) at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8) at android.os.Handler.handleCallback(Handler.java:959) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.os.HandlerThread.run(HandlerThread.java:85) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138) at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:816) at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0)  at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8)  at android.os.Handler.handleCallback(Handler.java:959)  at android.os.Handler.dispatchMessage(Handler.java:100)  at android.os.Looper.loopOnce(Looper.java:232)  at android.os.Looper.loop(Looper.java:317)  at android.os.HandlerThread.run(HandlerThread.java:85)  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent com.google.android.gms.auth.api.signin.GoogleSignInClient.getSignInIntent()' on a null object reference at com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth.signIn(GoogleAuth.java:81) at java.lang.reflect.Method.invoke(Native Method)  at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)  at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:816)  at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0)  at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8)  at android.os.Handler.handleCallback(Handler.java:959)  at android.os.Handler.dispatchMessage(Handler.java:100)  at android.os.Looper.loopOnce(Looper.java:232)  at android.os.Looper.loop(Looper.java:317)  at android.os.HandlerThread.run(HandlerThread.java:85) 

Yeahh man i found the issue come mail me i'll send you the zip file
[email protected]

@MalikHamza007
Copy link
Author

Hello everyone,

i have solved the issue and it works perfecto even the app has gone into production.
Now here me out everyone except creating your own client ids from the google cloud console use firebase add your web ,android ,ios and enable google authentication from the fireBase this is the important step and then go to google cloud console select your firebase project from there and use the ids.Now our setup is ready and we come to code make sure that to test the app natively the build apk will be made from that system whose sha-1 fingerprints are added to firebase.

In the code initialize the pluggin in the page or component where your are using Google login and use your web client id for every configuration just add your android client id in the capacitor config ts or json. Trust me this will work.

For the android don't forget to add your permissions , your configuration in the strings.xml and registering the pluggin in the Main Activity Java.

If you need more Help I'll send you the zip file of my project just do npm i and your good to go
This is my mail '[email protected]'

@PatricioRedegal
Copy link

I have tested with Capacitor 6, and it works correctly.

This is my code:

let googleClientId;
if (Capacitor.getPlatform() === 'web') {
  googleClientId = this.webClientId;
} else if (Capacitor.getPlatform() === 'android') {
  googleClientId = this.webClientId;
} else if (Capacitor.getPlatform() === 'ios') {
  googleClientId = this.iosClientId;
} else {
  console.error('Not supported');
}
await GoogleAuth.initialize({
  clientId: googleClientId,
});

const googleUser = await GoogleAuth.signIn();

On iOS, send the iOS key.
For Android, you need to create the project in Firebase, add the SHA-1 from the developer and production environments (in Android, you must obtain the SHA-1 from the Play Console for it to work once the version is published), and download the google-services.json file and place it in the project.

After this, on Android, send the web key, not the Android key.

@riderx
Copy link
Contributor

riderx commented Oct 14, 2024

https://github.com/Cap-go/capacitor-social-login is now the official alternative, if you need more robust login please migrate, it's 99% the same API
CleanShot 2024-10-14 at 15 51 02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants