19

Hi we are developing Xamarin application where we want monitor how many peoples install application from our referral id.

Im find this document https://developers.google.com/analytics/devguides/collection/android/v4/ where it says "Copy the google-services.json file you just downloaded into the app/ or mobile/ directory of your Android Studio project.".

I have visual studio (2013) project where these folders are missing of course. Question is, where i add the google-services.json file in visual studio project ?

Thanks in advance

Daniele D.
  • 2,624
  • 3
  • 36
  • 42
puko
  • 2,819
  • 4
  • 18
  • 27
  • 2
    There's now documentation at "Add the Google Services JSON File", https://developer.xamarin.com/guides/android/application_fundamentals/notifications/remote-notifications-with-fcm/ . – James Moore Mar 08 '17 at 22:03
  • The accepted answer is no longer correct. Please consider updating the accepted answer to @snotyak's answer below. – masterwok Dec 28 '18 at 19:38

3 Answers3

25

I don't know when it became necessary, but as I'm posting this (in May 2017), it is necessary. I placed mine in the same directory that my Android .csproj file was located. I then added it to the project and made sure that Xamarin.GooglePlayServices.Base.targets was in my .csproj. I read that rebuilding would be sufficient for making the proper build action to appear, but building and restarting XS is what did it for me. The final result in my .csproj was this:

<ItemGroup>
    <GoogleServicesJson Include="google-services.json" />
</ItemGroup>
Renats Stozkovs
  • 2,549
  • 10
  • 22
  • 26
snotyak
  • 3,709
  • 6
  • 35
  • 52
  • It depends on the version of Xamarin.GooglePlayServices you are using. For example in the 29.0.2 the task GoogleServicesJson don't exist. Only in newer versions. – jzeferino Jul 20 '17 at 10:58
  • 4
    Hi, Is it possible to have multiple `GoogleServicesJson` `ItemGroup` by using `Condition` statements in `.csproj`? – david Jan 23 '18 at 07:25
  • It's a shame that people post an answer and not respond to any comments after. – Denny Sep 18 '18 at 11:40
  • 1
    What does that mean "Xamarin.GooglePlayServices.Base.targets was in my .csproj"? That is not a library, so what is the syntax exactly? – Gerry Mar 11 '19 at 18:42
  • Totally nailed it Nov 2019 – niico Nov 16 '19 at 21:03
  • I tried adding the Xamarin.GooglePlayServices.Base package, unload the project, add the line to the cproj, reload the project, and it didn't work. I had to shut down and restart Visual Studio. The usual madness.... – andycted Apr 21 '23 at 09:23
15
  1. Go to your solution using file explorer and Copy the google-services.json inside Droid folder.
  2. Open visual studio and go to solution explorer.
  3. Right click on Droid project -> Add -> Existing Item and select google-services.json from file browse (it will added google-services.json to the solution).
  4. Right click on the google-services.json and go to properties.
  5. In the Properties pane, set the Build Action to GoogleServicesJson.


An example from MSFT Documentation: https://learn.microsoft.com/en-us/appcenter/sdk/push/migration/xamarin-android#3-google-servicesjson

Alireza Sattari
  • 181
  • 2
  • 12
  • GoogleServicesJson never appears in the Build Action. I've closed and re-opened the app, it's definitely in the Android app in Xamarin.Forms. Any ideas? – niico Nov 16 '19 at 20:31
  • I have tried this with Xamarin.Android in vs2017, it had worked fine for me following above steps. – Kasun Wanniarachchi Dec 12 '19 at 08:30
  • 4
    @niico add Xamarin.GooglePlayServices.Base to your project via Nuget, and reload your project. Then it should show up – 2Toad Mar 07 '20 at 01:37
10

In order to have the option of set Build Action to GoogleServicesJson you should install Xamarin.GooglePlayServices.Base via Nuget first. then close VS and reopen.

David Rechtman
  • 193
  • 1
  • 7