CodetrixStudio / CapacitorGoogleAuth

Capacitor plugin for Google Auth. Lightweight & no dependencies.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GoogleAuth.signIn Ionic 6 Android - "Something went wrong","code":"10"

abhisant opened this issue · comments

I have been stuck on this for a while. I am using IONIC 6, Sign in With Google works for IOS and Web but doesn't work for Android.
Can someone guide how to proceed? I need to get it working in Android using IONIC.


{message: 'Something went wrong', code: '10'}

These are the changes that I have made:

MainActivity.java

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

Strings.xml added -
Added web_cilent_id

I created the following - (but didn't use Andriod client id anywhere).
image

It works for web, ios, but doesn't work for Android.

It gives the following error --
D/CompatibilityChangeReporter: Compat change id reported: 78294732; UID 10159; state: ENABLED
D/Capacitor: Unable to find a Capacitor plugin to handle requestCode, trying Cordova plugins 147138663
D/Capacitor: Sending plugin error: {"save":false,"callbackId":"1887292","pluginId":"GoogleAuth","methodName":"signIn","success":false,"error":{"message":"Something went wrong","code":"10"}}

commented

When it's code "10" in Android, its usually a SHA-1 issue. Do check if your SHA-1 is configured properly where there is 1 inside google play if you configure the app to be signed under google play, and another in your android studio which you use to debug.

If the above is true, then make sure both SHA-1 are inside the cloud console, which you will need to create 2 separate android configurations to take it in.

I do recommend using firebase to create the cloud console configuration for this as the UI makes it more straight forward and helps to avoid mistakes that are otherwise hard to spot if you create credentials on the cloud console directly

This issue in another repo might be able to help you understand it better:
googlesamples/google-services#360

Thanks @AlvinTCH
My app is still under development, it's not yet published to Google Play Store.

I generated SHA1 using the following tool -
image

I copied the value of - "SHA1: " in the following -
image

commented

is your android app client id using the android client id or the web id?

Web id @AlvinTCH

I have made changes to Strings.xml too with web client id

commented

Same problem, my project with capacitor response with error code 10.

Me too changes in strings.xml file with web client id.

Capacitor config:
{ "appId": "", "appName": "", "webDir": "www", "bundledWebRuntime": false, "allowMixedContent": true, "plugins": { "GoogleAuth": { "scopes": ["profile", "email"], "iosClientID": "", "androidClientID": "webclientid.apps.googleusercontent.com" } } }

It worked finally. I deleted the android directly and recreated it using ionic commands. Made changes to MainActivity and Strings.xml.

@jrodriguer this is my capacitor config.

{
"appId": "<>",
"appName": "<>",
"webDir": "build",
"bundledWebRuntime": false,
"plugins": {
"GoogleAuth": {
"scopes": ["profile","email"],
"clientId" : "IOS_CLIENT_ID.apps.googleusercontent.com", (needed for ios - value is ios client id)
"serverClientId": "WEB_CLIENT_D.apps.googleusercontent.com", (needed for android - the value is webclientid and not android)
"forceCodeForRefreshToken": true
}
}
}

@jrodriguer - "androidClientID" should be replaced with "serverClientId"

When it's code "10" in Android, its usually a SHA-1 issue. Do check if your SHA-1 is configured properly where there is 1 inside google play if you configure the app to be signed under google play, and another in your android studio which you use to debug.

If the above is true, then make sure both SHA-1 are inside the cloud console, which you will need to create 2 separate android configurations to take it in.

I do recommend using firebase to create the cloud console configuration for this as the UI makes it more straight forward and helps to avoid mistakes that are otherwise hard to spot if you create credentials on the cloud console directly

This issue in another repo might be able to help you understand it better: googlesamples/google-services#360

I think that you have done me a great favour!