CodetrixStudio / CapacitorGoogleAuth

Capacitor plugin for Google Auth. Lightweight & no dependencies.
MIT License
284 stars 158 forks source link

Android fails (Unable to find a Capacitor plugin to handle requestCode) #147

Open sbellver opened 3 years ago

sbellver commented 3 years ago

Hi all.

I'm on Capacitor 3 and Vue 2 (quasar framework).

In iOs all works fine.

In android, when I click on the button shows the gmail accounts. Then select the account and notching happens .

I can see in the log:

V/Capacitor/Plugin: To native (Capacitor plugin): callbackId: 115059358, pluginId: GoogleAuth, methodName: signIn
V/Capacitor: callback: 115059358, pluginId: GoogleAuth, methodName: signIn, methodData: {}
D/Capacitor: App paused
D/Capacitor: Unable to find a Capacitor plugin to handle requestCode, trying Cordova plugins 578501389
E/Capacitor/Plugin: Something went wrong
    com.google.android.gms.common.api.ApiException: 10: 
...

It's like the plugin are not present in android target.

But If I run npx cap sync android:

[info] Found 1 Cordova plugin for android:
       onesignal-cordova-plugin@2.11.4
✔ copy android in 301.38ms
✔ Updating Android plugins in 10.24ms
[info] Found 4 Capacitor plugins for android:
       @capacitor-community/facebook-login@3.1.1
       @capacitor/camera@1.0.5
       @capacitor/geolocation@1.1.0
       @codetrix-studio/capacitor-google-auth@3.0.2
⠙ update android [info] Found 1 Cordova plugin for android:
       onesignal-cordova-plugin@2.11.4
✔ update android in 103.05ms

In androidClientId I set the name of de app: domain.name

I set server_client_id as google-services.json and copy this file into android/app/

I register the plugin in MainApplication.java

import com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth;

public class MainActivity extends BridgeActivity {
  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        registerPlugin(com.getcapacitor.community.facebooklogin.FacebookLogin.class);
        registerPlugin(GoogleAuth.class);
    }
}

But doesn't work in android.

aguirrel commented 3 years ago

Hi guys, I have the same problem. Any update?

sbellver commented 3 years ago

I'm in the same situation, any change.

I see maybe the error is ApiException: 10 ( https://github.com/CodetrixStudio/CapacitorGoogleAuth/issues/15 ) but have not success after change SHA1 in firebase for production & devel

To get the sha1 for your app, if helps:

keytool -list -v -keystore ~/path/to/myApp.Keystore -alias myAlias

Maybe is not compatible with Capacitor 3 & Android yet?

aguirrel commented 3 years ago

I think main problem is the SHA1 fingerprint, using keytool didn't work, when I tried to create an Andodroid API from google console it didn't accepted it.

So I solved it doing the following:

1 - https://stackoverflow.com/a/34223470 , option 2: Work with Google Maps Activity

2 - Then go to google console, create a new oath for android and use the SHA1 you got from stackoverflow solution.

3 - After that you shoud go to firebase, create a new project but be carefull there, when ask for project name wait until show all yours google console projects (don't create a new one from scratch) and select the project from 2.

4 - Activate google auth and copy the client id web from Firebase and use THIS code, not the google console one.

I followed a lot of steps but none of them was very specific about this point which is the most strange to me. Please if you need more detail in some point let me know.

Read1337 commented 3 years ago

I'm having the same issue. It works on IOS and web but I cannot login in an android device.

sbellver commented 3 years ago

I'm still blocked.

If I run

keytool -list -v \
-alias androiddebugkey -keystore ~/.android/debug.keystore

I get an SHA1

If I run @aguirrel solution, I have another one.

Well, I create a new Oauth Credential in https://console.cloud.google.com/apis/credentials?project=MYPROJECT

image

Then, go to firebase: https://console.firebase.google.com/project/MYPROJECT/settings/general/android:my.app

And add the another SHA1 (from Google Maps hint)

image

Then go back to My Credentials, and copy ID KEY from web client

image

And then copy this id into code

image

But no result, always have error API 10

sjdrew commented 2 years ago

And me too with same error. Works on web and ios, but not android. I am just testing in android emulator, but tried with the signed apk and debug with same error.

sjdrew commented 2 years ago

OK I fixed my issue. Turns out it seems the google-services.json I had in place for push notifications then overrides any client key in google api console.

What I did:

Then bingo, no more error code 10.

lmfmaier commented 2 years ago

I can't get this to work with capacitor 3.

The dialog with the google account selection shows up but when i select an account it's com.google.android.gms.common.api.ApiException: 10

I'm pretty sure my SHA1 is correct, Gradle signing report and keytool show the same fingerprint and I use it for the android app links too

no matter if I use the android client id or the web client id, it's always exception time

websystems-dev commented 2 years ago

After many hours with SHA1, keys, clients ID, etc... I finally found (here) the solution that worked for me. I simply added <string name="server_client_id">REPLACEME.apps.googleusercontent.com</string> in this file: android/app/src/main/res/values/strings.xml Now sign-in progress is OK and no more console error shown. I did other tests, and I figure out that google-services.json file seems to be useless. If I remove it, everything keeps to work fine. Even in the capacitor.config.json the value for androidClientId seems to be ininfluent. I tried with a foo value, and I still have no errors. I report this just for reference - i.e: I will keep anyway json file and androidClientId in their places. I'm using Capacitor 3

lmfmaier commented 2 years ago

After many hours with SHA1, keys, clients ID, etc... I finally found (here) the solution that worked for me. I simply added <string name="server_client_id">REPLACEME.apps.googleusercontent.com</string> in this file: android/app/src/main/res/values/strings.xml Now sign-in progress is OK and no more console error shown. I did other tests, and I figure out that google-services.json file seems to be useless. If I remove it, everything keeps to work fine. Even in the capacitor.config.json the value for androidClientId seems to be ininfluent. I tried with a foo value, and I still have no errors. I report this just for reference - i.e: I will keep anyway json file and androidClientId in their places. I'm using Capacitor 3

That did the trick!

mmarifat commented 2 years ago

@sjdrew Thanks man. Saved my day. Though I didn't follow the whole procedure. I just copy-paste the "type: 3" id instead of "type: 1"