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

I get this error: Error: "GoogleAuth" plugin is not implemented on android #116

Open
alessandrolombardini opened this issue Jun 11, 2021 · 49 comments

Comments

@alessandrolombardini
Copy link

I'm going crazy, I can't find a way to fix it. Does anyone know how to do it?

@chitkosarvesh
Copy link

I have the same problem! Please help!

@handihow
Copy link

same

@handihow
Copy link

Okay, I resolved this issue
I had to update Capacitor to version 3
https://capacitorjs.com/docs/updating/3-0
After I took all the steps, the error disappeared.

@kevinfavv
Copy link

Same problem,
My capacitor is already in 3.0.0, and the GoogleAuth class is not loaded.
Any informations?

image

@handihow
Copy link

handihow commented Jun 15, 2021

yes, you should remove the import of the Google Auth plugin of the MainActivity.java

https://capacitorjs.com/docs/updating/3-0#switch-to-automatic-android-plugin-loading

this means you can comment out / remove the import com.codetrix.....

and also the code inside the BridgeActivity

Make sure that you have installed "@capacitor/cli": "^3.0.1" in the dev dependencies

When you run npx cap sync android, you will see that capacitor now installs all the plugins automatically

@LuisMSotamba
Copy link

LuisMSotamba commented Jun 20, 2021

I followed all the steps for update from capacitor 2 to 3, but I get the same problem. "GoogleAuth.init()" is not implemented on android.

@FabioGoncalves
Copy link

Yeah, I am having the same problem, and if I remove the init(), it keeps stuck in google form...

@DercilioFontes
Copy link

DercilioFontes commented Jun 20, 2021

"GoogleAuth.init()" is only for WEB (https://github.com/CodetrixStudio/CapacitorGoogleAuth#migrate-from-2-to-3).

For Android and iOS is not necessary. I added a condition for checking that:

import { Device, DeviceInfo } from "@capacitor/device";
import { GoogleAuth } from "@codetrix-studio/capacitor-google-auth";

... 

const onSignInGoogle = async () => {
    try {
      const deviceInfo = await Device.getInfo();

      if ((deviceInfo as unknown as DeviceInfo).platform === "web") {
        await GoogleAuth.init();
      }
      const googleUser = (await GoogleAuth.signIn());
 ...

For the original issue, it worked as commented here: #110

@FabioGoncalves
Copy link

I am doing just like that, but after I choose my Google account, it's always stuck, like this
202778109_586862822298065_4100728333317879213_n

@DercilioFontes
Copy link

@FabioGoncalves, what are the logs on the Android Studio or Chrome device Dev tools?

@emtiajium
Copy link

emtiajium commented Jun 23, 2021

const deviceInfo = await Device.getInfo();

After doing that I'm getting the error: "Device" plugin is not implemented on android

@DercilioFontes
Copy link

DercilioFontes commented Jun 23, 2021

@emtiajium ,

Follow the guide for upgrading Capacitor. It will solve that.

https://capacitorjs.com/docs/updating/3-0

Comment or remove the onCreate method override. It is not necessary anymore.

Switch to automatic Android plugin loading

In Capacitor 3, it is preferred to automatically load the Android plugins. In MainActivity.java, the onCreate method can be removed. You no longer have to edit this file when adding or removing plugins installed via npm.

 public class MainActivity extends BridgeActivity {
//    @Override
//    public void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//
//        // Initializes the Bridge
//        this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
//            // Additional plugins you've installed go here
//            add(Plugin1.class);
//            add(Plugin2.class);
//       }});
//   }
 }

But for using the GoogleAuth, you need to register it like that:

import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth;

public class MainActivity extends BridgeActivity {

     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

        registerPlugin(GoogleAuth.class);
     }

}

https://capacitorjs.com/docs/updating/3-0#switch-to-automatic-android-plugin-loading

@codemickey78
Copy link

I followed all the steps but I get an error "c.NativePromise is not a function". Please help find solution to this issue and if possible those who have it work can share their knowledge on the steps and possibly share an example github repo to reference. Thanks in advance

@DercilioFontes
Copy link

@codemickey78,

Give more info about what you are trying to achieve. Where and when does this error happen?

@codemickey78
Copy link

@DercilioFontes

I'm using Ionic Capacitor 3 for my app and I need to authenticate user with Google SignIn. At first, I was using the GooglePlus capacitor plugin which wasn't working but later found out that the CodetrixStudio/CapacitorGoogleAuth was best to integrate.

I used that in my project which worked on iOS without any error but fails on Android with error "c.NativePromise is not a function" which happens to log an error "window.Capacitor.triggerEvent is not a function"

@DercilioFontes
Copy link

@codemickey78 ,

I don't know. The best I found was that about dev environment using https, but working with http.

ionic-team/capacitor#4056

@FabioGoncalves
Copy link

FabioGoncalves commented Jun 24, 2021

@DercilioFontes This works on Chrome, but on android was not working: this was like, 4 days ago.
Today: Is already working :o, maybe I should've waited 💯
Thank you, for all the supp guys!

@codemickey78
Copy link

@FabioGoncalves can you please help me solve it?
this is the error I'm getting.
👇🏽👇🏽👇🏽
Screenshot 2021-06-24 at 12 13 39 PM

@FabioGoncalves
Copy link

Do you have capacitor 3?
Did you follow all the instructions, put the server_client_id in strings.xml, the google-signin-client_id in index.html and added the plugin in the capacitorConfig.json?

Btw, I answered here #109

@emtiajium
Copy link

Do you have capacitor 3?
Did you follow all the instructions, put the server_client_id in strings.xml, the google-signin-client_id in index.html and added the plugin in the capacitorConfig.json?

Btw, I answered here #109

I'm also facing the issue, did everything, it works fine for the Web app and neither does for the Android app. I guess it happens because of the "Authorized JavaScript origins", as it does not allow to set the IP address.

@codemickey78
Copy link

@FabioGoncalves Yes, I'm using Capacitor 3, I have configured everything too.
Check them here👇🏽
Screenshot 2021-06-24 at 1 40 43 PM
👇🏽
Screenshot 2021-06-24 at 1 20 44 PM

Screenshot 2021-06-24 at 1 40 29 PM

@emtiajium were you able to make it work?

@FabioGoncalves
Copy link

FabioGoncalves commented Jun 24, 2021

Well, are you sure that the error that you showed is about this plugin? I didn't have any error like that one...

That server_client_id, is this one?
image
You added the SHA1 in firebase and enabled the google log in?
image

If so, I am not seeing the problem... the same thing was happening to me, but at least I could choose a google account and then I was stuck in that img that I inserted and that you have to make it too.

@emtiajium
Copy link

@FabioGoncalves Yes, I'm using Capacitor 3, I have configured everything too.
Check them here👇🏽
Screenshot 2021-06-24 at 1 40 43 PM
👇🏽
Screenshot 2021-06-24 at 1 20 44 PM

Screenshot 2021-06-24 at 1 40 29 PM

@emtiajium were you able to make it work?

I added the key in the XML file that is generated by the Firebase (Android client for com.x.y (auto created by Google Service))
BTW, used the other key, (Web client key) for the web app.

So, web app is working and Android app is not

@FabioGoncalves
Copy link

You have to use the same Web client key!!

@emtiajium
Copy link

emtiajium commented Jun 24, 2021

You have to use the same Web client key!!

Tried with the web client key at the index.html, strings.xml and capacitor.config.json but it produced the same result. When I click the sign-in button, I am able to select the Google user, but after that, it returns me nothing (from the GoogleAuth.signIn())

I couldn't figure it out!

@codemickey78
Copy link

Finally I solved it 🥳🥳🥳
But when I select the account, I'm stuck at confirmation popup to allow user. On clicking the "Allow" button it loads the same popup again.

@FabioGoncalves
Copy link

Yeah, I was in the same situation, but after 2-3 days when I went check again, it was working... xD

@LuisMSotamba
Copy link

LuisMSotamba commented Jun 24, 2021

@DercilioFontes

I'm using Ionic Capacitor 3 for my app and I need to authenticate user with Google SignIn. At first, I was using the GooglePlus capacitor plugin which wasn't working but later found out that the CodetrixStudio/CapacitorGoogleAuth was best to integrate.

I used that in my project which worked on iOS without any error but fails on Android with error "c.NativePromise is not a function" which happens to log an error "window.Capacitor.triggerEvent is not a function"

I did not get CodetrixStudio/CapacitorGoogleAuth to work in my project . Instead, I had to change to Ionic Google Plus https://ionicframework.com/docs/native/google-plus. I followed all the instructions and its worked in my Angular-Ionic project. I am using capacitor.

Summarizing it. Install the needed packages and sync it.

npm install cordova-plugin-googleplus
npm install @ionic-native/google-plus
ionic cap sync 

Inside app.module import GooglePlus
import { GooglePlus } from '@ionic-native/google-plus/ngx';
and insert it as provider.

In you login page, insert:

import { GooglePlus } from '@ionic-native/google-plus/ngx';

constructor(private googlePlus: GooglePlus) { }

...

this.googlePlus.login({})
  .then(res => console.log(res))
  .catch(err => console.error(err));

See https://github.com/EddyVerbruggen/cordova-plugin-googleplus#usage for replace empty object inside googlePlus.login()

Create credentials in Console google https://console.cloud.google.com/
Capture
You need SHA-1 certificate thumbprint. For this step, run powershell and go to the directory: C:\Users\your_name_user\.android. Inside this folder, you will find debug.keystore file.
Run the following command: keytool -keystore debug.keystore -list -v
You get the SHA-1 certificate fingerprint needed for create the google's credentials.

Once you had create the credentials and you had setup your project, run the project on android emulator or physical device and test it.

@codemickey78
Copy link

Well I have it working on android now with CodetrixStudio/CapacitorGoogleAuth 🥳✌🏽
Ready to launch my app 🚀🔥

@FabioGoncalves
Copy link

What have you done? Just waited? 😅

@codemickey78
Copy link

What have you done? Just waited? 😅

@FabioGoncalves I tested it on an emulator and it worked!

@FabioGoncalves
Copy link

@codemickey78 nice! I am glad you could make it!

@codemickey78
Copy link

codemickey78 commented Jun 27, 2021

@FabioGoncalves my app is live now on AppStore & PlayStore
still waiting for Google to approve it but it available on Apple

http://onelink.to/e32a9r
SocaSnap Feature Graphic

@brightchip
Copy link

How to fix the error :"Error: "GoogleAuth" plugin is not implemented on android"

@DercilioFontes
Copy link

@emtiajium ,

Follow the guide for upgrading Capacitor. It will solve that.

https://capacitorjs.com/docs/updating/3-0

Comment or remove the onCreate method override. It is not necessary anymore.

Switch to automatic Android plugin loading
In Capacitor 3, it is preferred to automatically load the Android plugins. In MainActivity.java, the onCreate method can be removed. You no longer have to edit this file when adding or removing plugins installed via npm.

 public class MainActivity extends BridgeActivity {
//    @Override
//    public void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//
//        // Initializes the Bridge
//        this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
//            // Additional plugins you've installed go here
//            add(Plugin1.class);
//            add(Plugin2.class);
//       }});
//   }
 }

But for using the GoogleAuth, you need to register it like that:

import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth;

public class MainActivity extends BridgeActivity {

     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

        registerPlugin(GoogleAuth.class);
     }

}

https://capacitorjs.com/docs/updating/3-0#switch-to-automatic-android-plugin-loading

@brightchip, have you done that?

@brightchip
Copy link

I kept the Main Activity default as It says "Cannot resolve symbol 'codetrixstudio'"
@DercilioFontes

@DercilioFontes
Copy link

DercilioFontes commented Jul 15, 2021

@brightchip, have you updated to Capacitor 3 and capacitor-google-auth 3?

"@capacitor/cli": "^3.0.1", "@codetrix-studio/capacitor-google-auth": "^3.0.1",

And used as:
`import { GoogleAuth } from "@codetrix-studio/capacitor-google-auth";`

- https://www.npmjs.com/package/@codetrix-studio/capacitor-google-auth
- https://capacitorjs.com/docs/updating/3-0

When building for Android, it will import it automatically.

Screen Shot 2021-07-15 at 1 33 17 AM

@brightchip
Copy link

Yes I just installed it recently
"@capacitor/android": "^3.0.1", "@capacitor/cli": "^3.1.1", "@capacitor/core": "^3.0.1", "@capacitor/ios": "^3.0.1", "@chrisbielak/svg-module": "^0.1.8", "@codetrix-studio/capacitor-google-auth": "^3.0.2",

@brightchip
Copy link

Oh wait. Thanks a lot! It got fixed I just have to run npx cap update android

@titib
Copy link

titib commented Aug 18, 2021

@DercilioFontes
I'm using Ionic Capacitor 3 for my app and I need to authenticate user with Google SignIn. At first, I was using the GooglePlus capacitor plugin which wasn't working but later found out that the CodetrixStudio/CapacitorGoogleAuth was best to integrate.
I used that in my project which worked on iOS without any error but fails on Android with error "c.NativePromise is not a function" which happens to log an error "window.Capacitor.triggerEvent is not a function"

I did not get CodetrixStudio/CapacitorGoogleAuth to work in my project . Instead, I had to change to Ionic Google Plus https://ionicframework.com/docs/native/google-plus. I followed all the instructions and its worked in my Angular-Ionic project. I am using capacitor.

Summarizing it. Install the needed packages and sync it.

npm install cordova-plugin-googleplus
npm install @ionic-native/google-plus
ionic cap sync 

Inside app.module import GooglePlus
import { GooglePlus } from '@ionic-native/google-plus/ngx';
and insert it as provider.

In you login page, insert:

import { GooglePlus } from '@ionic-native/google-plus/ngx';

constructor(private googlePlus: GooglePlus) { }

...

this.googlePlus.login({})
  .then(res => console.log(res))
  .catch(err => console.error(err));

See https://github.com/EddyVerbruggen/cordova-plugin-googleplus#usage for replace empty object inside googlePlus.login()

Create credentials in Console google https://console.cloud.google.com/
Capture
You need SHA-1 certificate thumbprint. For this step, run powershell and go to the directory: C:\Users\your_name_user\.android. Inside this folder, you will find debug.keystore file.
Run the following command: keytool -keystore debug.keystore -list -v
You get the SHA-1 certificate fingerprint needed for create the google's credentials.

Once you had create the credentials and you had setup your project, run the project on android emulator or physical device and test it.

@LuisMSotamba Thank you for your solution. It is much easier than with CodetrixStudio/CapacitorGoogleAuth

@rafraph
Copy link

rafraph commented Jan 10, 2022

I'm using ionic with capacitor for my project and in my case the gmail sign in worked with in following cases:

  • ionic simulator
  • android simulator
  • run from android studio on real device (with the play button)
  • create signed app and install it on real device with bundletool

But - when I put it in the play store and install it on real device for internal test, the sign it not working. I can choose the gmail account for the sign it, but after I clicked on this account it just return to my page without continue to complete the sign in.
Can it be related to "OAuth consent screen" in GCP?

@rafraph
Copy link

rafraph commented Jan 10, 2022

It took me a lot of time to fix this issue, so I will summarize here what works for me, to save time to other good people. I also used the information from this page especially from @FabioGoncalves and @DercilioFontes - thanks!
MainActivity.java

import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth;

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

index.html
add meta tag with the client_id. In my case I upload the application to play store with upload key, and google signed the app with signing key, so I need to use the SHA-1 of the signing key. So I need to go to my app in the google clound platform (GCP) -> API & Services -> Credentials and create new credentials for OAth 2.0 Client IDs. The type is Android, the package name is from AndroidManifest.xml and the SHA-1 is from my app in the google developer console -> Setup -> App Integrity -> and copy the SHA-1 of the App signing key certificate. Now you create the correct credentials. Copy the client ID that generated and use it in index.html like this:
<meta name="google-signin-client_id" content="************-**************************************.apps.googleusercontent.com">
replace the *** with your real client_id.

strings.xml
add the server_client_id. This is the client id of the web client in GCP-> API & Services -> Credentials. Add it like this:
<string name="server_client_id">**************-*************************************.apps.googleusercontent.com</string>

login page
The call for GoogleAuth.init(); is not needed for Android

@IssaYor
Copy link

IssaYor commented Oct 19, 2022

Reload gradle project in android studio

@IssaYor
Copy link

IssaYor commented Oct 19, 2022

I am doing just like that, but after I choose my Google account, it's always stuck, like this 202778109_586862822298065_4100728333317879213_n

you solved?

@jakowicz
Copy link

Reload gradle project in android studio

Underrated comment for newbies like myself

@Mohammad-Ismail-DEV
Copy link

Mohammad-Ismail-DEV commented Feb 7, 2024

@codetrix-studio/capacitor-google-auth
isn't working it's giving me an error with the message "Something went wrong".

something went wrong

@Rufai-Ahmed
Copy link

I have this same problem, but with version 5

@rasult22
Copy link

Guys do not forget adding this to your capacitor config: plugins: { GoogleAuth: { scopes: ['profile', 'email'], serverClientId: xxxxxxxxxxxxxxxxxxxxxxxxxi.apps.googleusercontent.com', forceCodeForRefreshToken: true, } },

@Rufai-Ahmed
Copy link

The issue with mine was that the package.json wasn't updating properly as I was installing the dependencies. So, it's a monorepo with a general dependency, and then ionic kinda generates its package.json and the dependencies' plugin wasn't updating there

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