Googleplayservicescomponents: ProcessGoogleServicesJson msbuild task not executed and do not generate resources

Created on 6 Jun 2017  路  7Comments  路  Source: xamarin/GooglePlayServicesComponents

Xamarin.Android Version (eg: 6.0):

7.3.1 (latest stable) with VS for Mac

Operating System & Version (eg: Mac OSX 10.11):

Mac OSX 10.12

Google Play Services Version (eg: 8.4.0):

Xamarin.GooglePlayServices.Basement 42.1021.1

Describe your Issue:

The MSBuild target ProcessGoogleServicesJson defined in the file GooglePlayServicesComponents/basement/buildtasks/Xamarin.GooglePlayServices.Basement.targets is not generating resource file when needed. eg: Resource like gcm_defaultSenderId (needed for Firebase to initialize successfully) are not added in the Resource.Designer.cs file.

Steps to Reproduce (with link to sample solution if possible):

  • Create a blank android project
  • Add package Xamarin.GooglePlayServices.Basement
  • Add a google-services.json from Firebase and set its build target to GoogleServicesJson
  • In MainActivity, add GetString(Resource.Strings.gcm_defaultSenderId);
  • Build the project, everything compile fine
  • Build the project once more, the resource is missing

Include any relevant Exception Stack traces, build logs, adb logs:

On the second build the file goog_svcs_json.xml in obj/Debug/res/values has been removed. but the stamp file in ProcessGoogleServicesJson.stamp in obj/Debug is still there so the msbuild target is not executed again against the google-services.json

Removing Inputs / Outputs parameters make the task to execute each time with no cache based on last modified date on file.

Most helpful comment

@mannyvw
If you have nuget package Xamarin.GooglePlayServices.Basement 42.1021.1, I would recommend adding lines below at the end of your android csproj (or at least after the line to import the targets file from the nuget package). That's what we used for the last 3 months as a workaround and it works perfectly.

<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>
</Target>

It will just override the target to include the google-services.json file without failing when not doing a clean build.

All 7 comments

This issue has been raised on xamarin bugzilla there : https://bugzilla.xamarin.com/show_bug.cgi?id=56108

And some discussions are available on Xamarin forums
https://forums.xamarin.com/discussion/96263/default-firebaseapp-is-not-initialized-in-this-process

Came across this post which may be related to what i have found in last week. I am using google storage on both ios and android, and had it working on both, however in the last week android has stopped working, and i cant get it working again even builds from few weeks ago that were working have now stopped (ios continues to work).

On android when I call InitializeApp it fails with

[FirebaseInitProvider] FirebaseApp initialization unsuccessful

I have tried downloading a new json file from existing app on console (triple checking bundle id matches), json file its set to build target to GoogleServicesJson, creating a new app on google console, and even creating a new project and app on google console.

Have added the line below suggested here after InitializeApp, compile sometimes fails on build but after a clean its ok. But at runtime this line throws an exception, Android.Content.Res.Resources+NotFoundException , is that expected as InitilizeApp fails or is that indication something else hasn't built ok?

var id = GetString(Resource.String.gcm_defaultSenderId);

Running out of ideas. Any help would be appreciated.

thanks

@mannyvw
If you have nuget package Xamarin.GooglePlayServices.Basement 42.1021.1, I would recommend adding lines below at the end of your android csproj (or at least after the line to import the targets file from the nuget package). That's what we used for the last 3 months as a workaround and it works perfectly.

<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>
</Target>

It will just override the target to include the google-services.json file without failing when not doing a clean build.

Spot on @Julien-Mialon thank you very much. Sorted!

Maybe @Redth could fix this issue for next release ?

This issue should finally be fixed in 60.1142.0-rc1 and newer :)

thank you @Julien-Mialon !!!! work for me!

Was this page helpful?
0 / 5 - 0 ratings