Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google login with cordova won't work. Error 10 in Android and bad request in IOS

I have a Android/IOS app build with cordova.

As I'm running the server with ssl now, I can't open with the inappBrowser the requests from google. So I have to use the native login, with this plugin. ( Which is the most reliable that I have found )

After reading many posts ( this, this, and .. ) I believe that the problem it's in the way I am (trying to) generate my key file

keytool -exportcert -keystore ~/.android/debug.keystore -list -v -alias myAppName

(with empty password ) it prompts

error de herramienta de claves: java.lang.Exception: El alias <myAppName> no existe (doesn't exist)
java.lang.Exception: El alias <myAppName> no existe
    at sun.security.tools.keytool.Main.doPrintEntry(Main.java:1738)
    at sun.security.tools.keytool.Main.doCommands(Main.java:1064)
    at sun.security.tools.keytool.Main.run(Main.java:343)
    at sun.security.tools.keytool.Main.main(Main.java:336)

Does that mean it didn't work?

About the error:

window.plugins.googleplus.login(
    {
      'scopes': 'profile email', 
      'webClientId': 'xxxxxxxxx.apps.googleusercontent.com', 
      'offline': true, 
    },
    function (obj) {
      alert(JSON.stringify(obj)); /
    },
    function (msg) {
      alert('error: ' + msg); // <--- It alerts 'error: 10'
    }
);

enter image description here

Any hint would be very welcome

-EDIT (this is now solved)-

Just tested in IOS (simulator) and the result is even worse: enter image description here

-EDIT 2-

I tried to install it both ways ( same result )

  • cordova plugin add cordova-plugin-googleplus --save --variable REVERSED_CLIENT_ID=myreversedclientid
  • cordova plugin add https://github.com/EddyVerbruggen/cordova-plugin-googleplus --save --variable REVERSED_CLIENT_ID=myreversedclientid

( And multiple times, before and after "setting" the .key )

-EDIT 3-

BTW, What does this error mean? ( can't find it, either )

like image 248
Toni Michel Caubet Avatar asked Oct 29 '25 09:10

Toni Michel Caubet


2 Answers

For me error 10 happened when the generated SHA1 by keytool(which i used to add the app to google) mismatched with the build apk's sha 1. How i fixed is by editing the SHA1 of the google project to the build apks SHA1.

1 - first, build the apk

cordova build android --device --verbose --stacktrace --debug

2 - see path to your apk. it will be in projectfolder/platforms/outputs/apk/android-debug.apk

3 - get the SHA1 of the apk

keytool -list -printcert -jarfile <path to your apk>

it will output the details which include SHA1. copy this and replace the SHA1 in google project app.

4 - go to firebase console open app edit the SHA1. copy the build apk's SHA1 to replace the previous SHA1 which we initially pasted on when creating the app.

like image 198
aimme Avatar answered Oct 31 '25 01:10

aimme


I don't seem to find a GoogleService-Info.plist file. In which folder should it be?

Since we talk about iOS I believe GoogleService-Info.plist file is missing and this is a problem. Please take a look on this EddyVerbruggen/cordova-plugin-googleplus

To get your iOS REVERSED_CLIENT_ID, generate a configuration file here. This GoogleService-Info.plist file contains the REVERSED_CLIENT_ID you'll need during installation. This value is only needed for iOS.

The REVERSED_CLIENT_ID is also known as the "iOS URL Scheme" on the Developer's Console.

Login on iOS takes the user to a SafariViewController through the Google SDK, instead of the separate Safari browser.

To generate a configuration file go to: https://developers.google.com/mobile/add?platform=ios

Locate this file in root of your iOS project


In my case the GoogleService-Info.plist file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CLIENT_ID</key>
    <string>18643434937-j6ofvkktk1uklqjv61ecr75f1llqki0f.apps.googleusercontent.com</string>
    <key>REVERSED_CLIENT_ID</key>
    <string>com.googleusercontent.apps.18643434937-j6ofvkktk1uklqjv61ecr75f1llqki0f</string>
    <key>PLIST_VERSION</key>
    <string>1</string>
    <key>BUNDLE_ID</key>
    <string>com.app.client</string>
    <key>PROJECT_ID</key>
    <string>app-c6c82</string>
    <key>IS_ADS_ENABLED</key>
    <false/>
    <key>IS_ANALYTICS_ENABLED</key>
    <false/>
    <key>IS_APPINVITE_ENABLED</key>
    <false/>
    <key>IS_GCM_ENABLED</key>
    <false/>
    <key>IS_SIGNIN_ENABLED</key>
    <true/>
    <key>GOOGLE_APP_ID</key>
    <string>1:68743434937:ios:b03bcd3b3f571a56</string>
</dict>
</plist>

For Android google-services.json:

Go to: https://developers.google.com/mobile/add?platform=android

and generate it there.

It should look like:

{
  "project_info": {
    "project_number": "68643434935",
    "project_id": "myapp-c6c82"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:68643434935:android:71bc3a4035ab9002",
        "android_client_info": {
          "package_name": "com.agan.armoa"
        }
      },
      "oauth_client": [
        {
          "client_id": "68643434935-mqm5s8lubfr5j5s3bj62eigbod0h083s.apps.googleusercontent.com",
          "client_type": 1,
          "android_info": {
            "package_name": "com.agan.armoa",
            "certificate_hash": "759A66458E30A70628F2E6A66C46240E21676B72"
          }
        },
        {
          "client_id": "68643434935-bc48465luu0r77tufpf4fumv0bd5pta2.apps.googleusercontent.com",
          "client_type": 3
        },
        {
          "client_id": "68643434935-gpdj67581deilm3refkgobuvneceisqt.apps.googleusercontent.com",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "AIzaSyDB6g1-nMbZ9aZkic2dCz8QrcqHfCSDrsw"
        }
      ],
      "services": {
        "analytics_service": {
          "status": 1
        },
        "appinvite_service": {
          "status": 1,
          "other_platform_oauth_client": []
        },
        "ads_service": {
          "status": 1
        }
      }
    },
    {
      "client_info": {
        "mobilesdk_app_id": "1:68643434935:android:b03bcd3b3f571a56",
        "android_client_info": {
          "package_name": "com.myapp.client"
        }
      },
      "oauth_client": [
        {
          "client_id": "68643434935-25ciu2gccfv70m08sc7c4fr3v0gqe89m.apps.googleusercontent.com",
          "client_type": 1,
          "android_info": {
            "package_name": "com.myapp.client",
            "certificate_hash": "E90A75A9AA4470337AE5ECD87C3416DDB1109BE1"
          }
        },
        {
          "client_id": "68643434935-bc48465luu0r77tufpf4fumv0bd5pta2.apps.googleusercontent.com",
          "client_type": 3
        },
        {
          "client_id": "68643434935-gpdj67581deilm3refkgobuvneceisqt.apps.googleusercontent.com",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "AIzaSyDB6g1-nMbZ9aZkic2dCz8QrcqHfCSDrsw"
        }
      ],
      "services": {
        "analytics_service": {
          "status": 1
        },
        "appinvite_service": {
          "status": 1,
          "other_platform_oauth_client": []
        },
        "ads_service": {
          "status": 1
        }
      }
    }
  ],
  "configuration_version": "1"
}

[EDIT 2]

About your error:

keytool -exportcert -list -v \ -alias project -keystore ~/.android/debug.keystore I get this error: error de herramienta de claves: java.lang.Exception: El archivo de almacén de claves no existe: /Users/toni/.android/debug.keystore java.lang.Exception: El archivo de almacén de claves no existe: /Users/toni/.android/debug.keystore

Try to run:

keytool -genkey -v -keystore ~/.android/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"

to generate ~/.android/debug.keystore

Also take a look: https://developer.android.com/studio/publish/index.html#debugmode

[EDIT 3]

error 10 means:

public static final int DEVELOPER_ERROR

The application is misconfigured. This error is not recoverable and will be treated as fatal. The developer should look at the logs after this to determine more actionable information.

Constant Value: 10

See DOCS and similar error solution: Error: Status{statusCode=DEVELOPER_ERROR, resolution=null}

like image 23
Maxim Shoustin Avatar answered Oct 31 '25 00:10

Maxim Shoustin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!