GoogleService failed to initialize
Asked Answered
K

10

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?

Killam answered 18/12, 2015 at 23:18 Comment(6)
is this in your manifest: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />Monastery
Look at the step 2: developers.google.com/identity/sign-in/android/start?hl=enOsmometer
I have tried both but still getting same message!Killam
Is you device play services apk updated ?Karaite
None of these solutions were working, but updating the Services APK seemed to do the trick!Fullblooded
Updating from "play-services:8.4.0" to 9.2.0 fixed this for meDekameter
O
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.

Osmund answered 21/12, 2015 at 3:39 Comment(17)
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 notCeja
@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!Estaminet
@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.Osmund
We already had the google-services.json in our app, but we had to recreate it when upgrading to 8.4.0.Ppm
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 keyBillmyre
@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.Osmund
@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.Delineation
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.Townscape
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.Govan
See correct response here from the product manager at Google: #34365869Zarzuela
@AhmedMounir : That is exactly the same answer as mine. I assume you wanted to comment this for answer by Alexander.Osmund
why is there no map service and just signin , analytics and cloud messaging services onlyUnthinking
@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 developers.google.com/maps/documentation/android-api/startOsmund
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.Unthinking
@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.Detestation
@Detestation 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.Osmund
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.Legacy
D
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.

Detestation answered 9/6, 2016 at 8:13 Comment(3)
For people who use gradle-experimental plugin, google-services.json will not take effect directly. Please refer to https://mcmap.net/q/169267/-gradle-plugin-google-services-does-not-work-with-gradle-experimental-0-6-0-alpha7 for workaround.Condign
Why is it mandatory to include the json file? Why can't I supply the id at runtime in code?Dees
File goes in /app dir, not top-level dir?Endogamy
O
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.

Osmund answered 21/12, 2015 at 3:39 Comment(17)
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 notCeja
@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!Estaminet
@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.Osmund
We already had the google-services.json in our app, but we had to recreate it when upgrading to 8.4.0.Ppm
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 keyBillmyre
@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.Osmund
@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.Delineation
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.Townscape
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.Govan
See correct response here from the product manager at Google: #34365869Zarzuela
@AhmedMounir : That is exactly the same answer as mine. I assume you wanted to comment this for answer by Alexander.Osmund
why is there no map service and just signin , analytics and cloud messaging services onlyUnthinking
@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 developers.google.com/maps/documentation/android-api/startOsmund
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.Unthinking
@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.Detestation
@Detestation 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.Osmund
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.Legacy
P
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

Pizza answered 28/12, 2015 at 17:55 Comment(3)
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?Terrence
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.0Pizza
@eosrei, using only com.google.android.gms:play-services-maps:8.4.0 worked for me, thanks !Extemporize
A
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"
    }
    
Artless answered 29/1, 2016 at 21:45 Comment(2)
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.Billmyre
@AndrewV. Yes I agree. The version "1.5.0-beta2" was copied from the link I gave above.Artless
Y
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.

Yvette answered 27/9, 2016 at 18:53 Comment(0)
B
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

Boresome answered 5/10, 2018 at 19:11 Comment(0)
D
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

Donkey answered 23/12, 2015 at 5:7 Comment(0)
N
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.

Narcotism answered 4/4, 2016 at 4:16 Comment(0)
P
0

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

Postern answered 24/11, 2016 at 21:43 Comment(0)
S
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

Subdeacon answered 28/2, 2017 at 10:26 Comment(1)
could ask question as commentLues

© 2022 - 2024 — McMap. All rights reserved.