113

I am using google Maps in my android application. I have created the key and added necessary permissions in manifest file. But soon I start the application I get this message in debugger:

GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services. Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.

I am not sure whats wrong. The Map is working fine and I can use it without any issues. My gradle file has this entry:

compile 'com.google.android.gms:play-services:8.4.0'

What is it complaining about and how do I alleviate it?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Zach
  • 9,989
  • 19
  • 70
  • 107

10 Answers10

52

[From Product Manager @ Google]

You can fix this issue by downloading and copying the google-services.json file for your Android app by following the steps below:

  • Select your app/project name and Android packagename from this link and click Continue to Choose and configure services.
  • Click Continue to Generate Configuration files.
  • Download google-services.json and copy the file to the app/ or mobile/ module directory in your Android project.

If you have previously imported your Google project into Firebase, you can get the updated google-services.json from the Firebase console under Project Settings.

DO NOT COPY the PROJECT_NUMBER as suggested by one of the other answers since the google_app_id refers to your app within a Project and not the project itself.

Community
  • 1
  • 1
Sriram
  • 1,174
  • 2
  • 9
  • 11
39

You need to place the configuration file (google-services.json) generated by developer.google.com, as mentioned in the 2nd step of the official docs here

The process is simple

  1. You can select your project or create a new one.
  2. Then after selecting desired services (in this case the maps service), you can generate the configuration file.

    For people who have migrated to the Firebase projects they can get the same by going to Firebase Console, selecting your project and under settings you will find the configuration file.

  3. Then as quoted in step 3 of the official docs here

    Copy the google-services.json file you just downloaded into the app/ or mobile/ directory of your Android

P.S : For people downvoting this answer, please do leave a comment as to why you are down voting it.

Nishant Srivastava
  • 4,723
  • 2
  • 24
  • 35
  • 6
    Do we actually need this in our apps with the new version of Google Play Services? Or is it just for Google sign in? Seems weird that the logs throw me errors as if I need it, but I might not – RED_ Jan 08 '16 at 12:13
  • 2
    @Radix...I went to the link that you shared, but it asked me to register for Google Sign In or Google Cloud Messaging...nothing about the map. Any idea? Also, copying this json file to right under /app is kind of odd...can you clarify? Thanks much! – Johnny Wu Jan 09 '16 at 14:46
  • @JohnnyWu thats because all these services are tied to Google Play Services and hence you need to sign in. Also You need the file under the app because thats how google set it up to read the file from. Its more like the path is hardcoded and thats how google services reads the file from. – Nishant Srivastava Jan 13 '16 at 05:04
  • 2
    We already had the google-services.json in our app, but we had to recreate it when upgrading to 8.4.0. – Roy Solberg Jan 22 '16 at 08:56
  • 1
    same issue, adding google-services.json didn't help, weird thing that it doesn't see my already activated gcm and wants to create each time own server key – Andrew V. Feb 01 '16 at 11:51
  • @AndrewV. I am guessing your implementation of API keys on Google Cloud and one defined in your json are different, otherwise I donot see a reason for this to not work. A more elaborate question of what you are doing would be helpful for anyone to answer your question. – Nishant Srivastava Feb 01 '16 at 12:21
  • @AndrewV, could you please check if you had added necessary permissions? Interestingly I got this error because I was missing permissions for ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION. – DarkoM Feb 09 '16 at 10:35
  • This should be the accepted answer. Just getting rid of the message is going to definitely being up the same work to be done in future. – JaydeepW Apr 13 '16 at 10:56
  • same issue here, using 8.4.0 I still need to add `R.string.google_app_id` to strings.xml if I want to get rid of that message. – cwhsu Apr 18 '16 at 03:37
  • 11
    See correct response here from the product manager at Google: http://stackoverflow.com/questions/34365369/googleservice-failed-to-initialize/37720340#37720340 – Ahmed Mounir Jun 27 '16 at 20:22
  • @AhmedMounir : That is exactly the same answer as mine. I assume you wanted to comment this for answer by Alexander. – Nishant Srivastava Jun 28 '16 at 05:27
  • why is there no map service and just signin , analytics and cloud messaging services only – Faisal Naseer Jul 08 '16 at 15:26
  • @FaisalNaseer because you need `google-services.json` to get Google Services working. The options provided are whats available through GoogleServices.Google Services is a dependency to Maps servcie, hence it needs to be resolved. To get your Maps working you need to get an API key , as instructed here https://developers.google.com/maps/documentation/android-api/start – Nishant Srivastava Jul 08 '16 at 19:52
  • Thanks @Radix I was continuously seeing particular error message and it was disturbing. actualy my map is displaying on some devices like emulator and Samsung J1 but unfortunately its not displaying o my tablet or Note2. I thought it may be the problem. – Faisal Naseer Jul 09 '16 at 04:24
  • @Radix your answer is quite similar to mine (thanks for adding the link to the Firebase console and the deep-link the download config file wizard), except that you've linked to the Sign-In docs twice in your answer which is a bit confusing since this issue can occur with any Google service such as GCM/FCM, Analytics, Sign-in etc. – Sriram Jul 11 '16 at 23:48
  • @Sriram The idea is to show the mention in official docs. The same section occurs in any Google Services, I just picked up signin as the one. – Nishant Srivastava Jul 18 '16 at 07:27
  • My app is logging "GoogleService failed to initialize", so I checked the services, but I don't care about any of these at this time. Guess I'll just ignore the error. – Gerry Dec 12 '16 at 18:35
11

In my case, the cause of this error was that the Google Services plugin for Gradle and the Play Services library were incompatible versions. Instructions for compatible versions:

1) Add the dependency to your project-level build.gradle:

classpath 'com.google.gms:google-services:1.5.0-beta2'

2) Add the plugin to your app-level build.gradle:

apply plugin: 'com.google.gms.google-services'

3) If you're using Android Studio, this is the string to add to the dependency section of your application's build.gradle file:

dependencies {
  compile "com.google.android.gms:play-services:8.3.0"
}

Source: https://developers.google.com/cloud-messaging/android/client

13rac1
  • 1,057
  • 11
  • 14
  • 1
    Thanks, but this didn't work for me - Android Studio insists I have the google-services.json file also installed, although I thought it unnecessary if you followed the three steps above which should override the need for the file? Which leads to me ask: Why do I need a Google User Sign-in system if all I'm providing is basic mapping? – iaindownie Jan 04 '16 at 13:58
  • 1
    My solution wasn't listed, so I answered the question to give people another potential solution for this problem. In your case, you may have extra libraries installed. Try only using the `com.google.android.gms:play-services-maps:8.4.0` – 13rac1 Jan 04 '16 at 21:56
  • @eosrei, using only com.google.android.gms:play-services-maps:8.4.0 worked for me, thanks ! – akshay7692 Sep 26 '16 at 13:09
4

I met the same problem and solved it followed the official solution.

Here are the steps:

  1. get the configuration file google-services.json from this link.

  2. Copy the google-services.json file you just downloaded into the app/ or mobile/ directory of your Android Studio project.

  3. Add the dependency to your project-level build.gradle:

    classpath 'com.google.gms:google-services:1.5.0-beta2'
    
  4. Add the plugin to your app-level build.gradle:

    apply plugin: 'com.google.gms.google-services'
    
  5. Add this dependency to your app-level build.gradle:

    dependencies {
        compile "com.google.android.gms:play-services:8.3.0"
    }
    
Sufian
  • 6,405
  • 16
  • 66
  • 120
Will
  • 496
  • 8
  • 14
  • 1
    I think better to use com.google.gms:google-services:1.5.0 as it's better then beta version to remove some unpredictable errors in your app. – Andrew V. Feb 01 '16 at 11:49
  • @AndrewV. Yes I agree. The version "1.5.0-beta2" was copied from the link I gave above. – Will Feb 01 '16 at 15:15
1

For those who face this problem even after correctly setting up play services and placing google-services.json file in project/app folder, the actual solution is to

Build > Rebuild Project

Possibly due to the fact that strings from json file are not integrated into compiled resources until a full rebuild is performed.

anandbibek
  • 1,659
  • 16
  • 20
1

For Xamarin/Visual Studio Mac I needed to add this to the bottom of my Droid.csproj

<Target Name="ProcessGoogleServicesJson" Condition=" '@(GoogleServicesJson)' != '' AND '$(AndroidApplication)' == 'True' AND '$(DesignTimeBuild)' != 'True'" BeforeTargets="$(ProcessGoogleServicesJsonBeforeTargets)" AfterTargets="$(ProcessGoogleServicesJsonAfterTargets)">
<Message Text="Using ProcessGoogleServicesJson override" Importance="high" />
<ProcessGoogleServicesJson GoogleServicesJsons="@(GoogleServicesJson)" IntermediateOutputPath="$(IntermediateOutputPath)" MonoAndroidResDirIntermediate="$(MonoAndroidResDirIntermediate)" AndroidPackageName="$(_AndroidPackage)">
    <Output ItemName="_AndroidResourceDest" TaskParameter="GoogleServicesGeneratedResources" />
    <Output ItemName="FileWrites" TaskParameter="GoogleServicesGeneratedResources" />
</ProcessGoogleServicesJson>
<ItemGroup>
    <FileWrites Include="$(IntermediateOutputPath)\ProcessGoogleServicesJson.stamp" />
</ItemGroup>

https://github.com/xamarin/GooglePlayServicesComponents/issues/64

stepheaw
  • 1,683
  • 3
  • 22
  • 35
0

This also happen to me. In my case, it is because Android studio tried to insert some code to my main activity. Removing the code fixes the error

Inserted code is about App Indexing:

https://developers.google.com/app-indexing/android/publish

Superbiji
  • 1,723
  • 2
  • 14
  • 21
0

I had the same issue back then. Was able to solve it by using only the necessary play services library, which in my case GCM.

Instead of com.google.android.gms:play-services:8.4.0, I use com.google.android.gms:play-services-gcm:8.4.0. See here for more info; this also solves multidex problem.

Then I applied both @Radix and @Alexander's approach to remove the message GCM has been output in the logcat regarding the google-services.json.

emen
  • 6,050
  • 11
  • 57
  • 94
0

You can change the versionCode and versionName of your app in your Gradle file.

Jameson
  • 6,400
  • 6
  • 32
  • 53
0

A quick fix I used is to disable signing. If you aren't wanting to create production code you can set your build variant to debug, localOldDebug or localDebug.

Click on Build Variants on the bottom left in Android Studio.

how-to-disable-generated-signed-apk-android-studio

Community
  • 1
  • 1
Dudas
  • 1
  • 2