Search code examples
androidsdkgoogle-plusgoogle-plus-signin

Google Play services is not available. This application will close


I'm quite new to android developement and I'm trying to run the Google Plus SDK sample android sample project from GitHub using Android Studio. I can able to run the app successfully in the AVD kitkat/lollipop device. But after opening the app if I select the checkbox for "Request server with auth code?" it display this,

Error: the value of WEB_CLIENT_ID or SERVER_BASE_URL is not set correctly. This will cause error when requesting with server auth code.

G+ sample app signin error

Screenshot - Click to enlarge

I've solved this error now see my answer. However I couldn't signin with google plus button.

UPDATE:

If I try running the same project in my mobile(physical device) running Lollipop 5.0.1 connected via usb the same error as above occurs(same as on AVD) and If I click "Sign in" button it displays to Choose an account popup. If I select my email and press ok. I have another error message displaying,

Google Play services is not available. This application will close.

But all the play services apps including Google+ app is installed on my phone and none of them are disabled. How can I solve this error and am I missing something obvious?


Solution

  • Problem 1: Error: the value of WEB_CLIENT_ID or SERVER_BASE_URL is not set correctly

    Open MainActivity.java and set the server base url and the client id of your web application token variable for your token exchange server that you created in the Google developer console,

    // Client ID for a web server that will receive the auth code and exchange it for a
    // refresh token if offline access is requested.
    private static final String WEB_CLIENT_ID = "YOUR_CLIENT_ID";
    
    // Base URL for your token exchange server, no trailing slash.
    private static final String SERVER_BASE_URL = "http://yourtokenexchangeserver.com";
    

    Problem 2: Google Play services is not available. This application will close.

    You have to create a Signing certificate fingerprint(SHA1) using the keytool in the terminal app and try running the app. More on this link.