28

I'm working with Xamarin-Android to make an application, so I need to set Build Action to my google-services.json file but there is no such Property as GoogleServicesJson, and when I try just to write it, it shows me an exception:

Exception of type 'System.Runtime.InteropServices.ExternalException' was thrown.

I tried to save and then restart Visual Studio, but it didn't solve the problem.

If you know how to solve this problem, please help me! :)
That's the file I'm clicking on

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
oceankit
  • 410
  • 1
  • 5
  • 8
  • I added screenshot to the whole solution, so you can see that I am clicking exactly on the file that is located in Xamarin.Android project. :) – oceankit Mar 08 '17 at 17:34
  • @SushiHangover Yes, but tried to do this in VS 2015, there is no difference – oceankit Mar 08 '17 at 17:36
  • @SushiHangover I added Xamarin.Firebase.Messaging, thought It is enough. But now when I added Xamarin.GooglePlayServices.Basement it can be set, Thank you very much! :D – oceankit Mar 08 '17 at 17:53
  • Try right click on file / properties / build actoin / googleservicesjson - fixed it for me. – niico Nov 12 '19 at 16:47

11 Answers11

57

The GoogleServicesJson build type comes from the Xamarin.GooglePlayServices.Basement.targets.

If your project does not have Xamarin.GooglePlayServices.Basement installed via one of its dependents, usually Xamarin.GooglePlayServices.Gcm or Xamarin.Firebase.Messaging if we are talking about messaging, then you will not have that build action available.

After adding a package that installs Basement, or manually adding it yourself, your .csproj will contain an import for Xamarin.GooglePlayServices.Basement.targets and GoogleServicesJson will be available as a build type:

.csproj import example:

  <Import Project="..\packages\Xamarin.GooglePlayServices.Basement.42.1001.0\build\MonoAndroid70\Xamarin.GooglePlayServices.Basement.targets" Condition="Exists('..\packages\Xamarin.GooglePlayServices.Basement.42.1001.0\build\MonoAndroid70\Xamarin.GooglePlayServices.Basement.targets')" />
SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • 1
    Thanks @SushiHangover. To anyone finding this, remember to update the version of Xamarin.GooglePlayServices.Basement and the relative path where it can be found in the import directive. Also, if you have more than one Android project in your solution, the path may be to a different project, not your current one, so you may need to do some digging with FileExplorer. – English Dave Feb 15 '19 at 18:45
  • 4
    If you don't see it after installed, just restart Visual Studio. – TPG Jun 27 '20 at 07:37
  • It's worth noting that I reference another VStudio project that has this NuGet dependency on Xamarin.Firebase.Messaging but the app project didn't. It compiles fine relying on the reference project NuGets but Visual Studio doesn't pick it up for the IDE build actions - more info here For me I added a firebase NuGet to ensure the build option appears - as per https://forums.xamarin.com/discussion/175159/i-didnt-find-googleservices-json-in-the-build-action? – RobbiewOnline Feb 15 '21 at 16:36
  • any specific version i need to use.. i have installed 71.1620.4 but i am not able to find GoogleServiceJson as build option – Neeraj Goel Oct 20 '21 at 05:02
  • Another note: you do only need to install the dependency into the project compiling the resouces (eg android project only) do not install this into xamarin.forms or even ios. this might just interefere with the linker and app size. – innom Mar 25 '22 at 12:31
26

Even after installing "Xamarin.GooglePlayServices.Basement" GoogleServiceJson option was not showing. Surprisingly but when i quit Xamarin studio and opened it again it starts displaying.

Venu Gopal Tewari
  • 5,672
  • 42
  • 41
7

1-Download first these Packages:

Xamarin.Firebase.Common

Xamarin.Firebase.Config

Xamarin.Firebase.Iid

Xamarin.GooglePlayServices.Base

Xamarin.GooglePlayServices.Basement

Xamarin.GooglePlayServices.Tasks

2-then restart and rebuild 3-from google-services.json --> Properties --> build Action: GoogleServicesJson

Suliman Farzat
  • 1,197
  • 11
  • 12
  • any specific version i need to use.. i have installed all the packages but i am not able to find GoogleServiceJson as build option.. – Neeraj Goel Oct 20 '21 at 05:02
  • All these packages are Android specific - need to install them only in Android project. Once done, rebuild all, close Visual Studio and open again. – Abhijith C R Apr 05 '22 at 05:55
3

In Visual Studio close the Project and reopen it. That worked for me:)

KPS250
  • 317
  • 4
  • 8
2

Download first these Packages:

enter image description here

then restart

enter image description here

Thum Choon Tat
  • 3,084
  • 1
  • 22
  • 24
Suliman Farzat
  • 1,197
  • 11
  • 12
  • Please add the package name into the text of your answer. Also, please change "enter image description here" to a description that is useful. – Tom Aranda Oct 28 '17 at 03:01
2

GoogleServiceJsom is coming from Xamarin.GooglePlayServices.Basement package. If it is not visible after the package installation restart your visual studio project, it will work

Parappattu
  • 41
  • 6
2

I tried installing every single package that people have suggested installing, I restarted my visual studio after each one, tried running as admin, restarted my computer, NOTHING would work. I could not get the GoogleServicesJson option to show up in my Build Actions list.

Looking at @SushiHangover 's comment, I tried just copying and pasting that line into my .shproj file and changed it to match the path to my nuget packages

  <Import Project="C:\Users\<my user>\.nuget\packages\xamarin.googleplayservices.basement\117.6.0.3\build\monoandroid90\Xamarin.GooglePlayServices.Basement.targets" Condition="Exists('C:\Users\<my user>\.nuget\packages\xamarin.googleplayservices.basement\117.6.0.3\build\monoandroid90\Xamarin.GooglePlayServices.Basement.targets')" />

And this is the only thing that would finally work for me. Hope that it helps someone else!

KNewton
  • 73
  • 4
0

I thougt i was doing it wrong but you dont get the Build action by rightklick it like a example from Mac enter image description here

PS You dont right klick on the Google-Services.json and see the Build avtion You press properties and then at the properties you find the Build action

enter image description here

Jonas
  • 185
  • 4
  • 16
0

While using AppCenter, I was not adding App centre and App Center Push packages to Android Dependencies folder. Upon adding GoogleServicesJson immediately showed up

sver
  • 866
  • 1
  • 19
  • 44
0

I was getting stuck with this because the Microsoft guide https://learn.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=windows which was saying to install Xamarin.GooglePlayServices.Base directly.

What worked: install Xamarin.GooglePlayServices.Gcm through Nuget

David Andrew Thorpe
  • 838
  • 1
  • 9
  • 23
0

In my case, I solved it by installing the Xamarin.GooglePlayServices.Basement package and restarting Visual Studio.