问题
I tried to follow the tutorial: Push notifications to Xamarin.Android (the iOS part works already)
But I get the following error at build time:
The "ProcessGoogleServicesJson" task was not given a value for the required parameter "ResStringsPath". ServiceToolStandard.Android
What I have so far:
- I've created a firebase project
- FirebaseConsole:
- downloaded the google-services.json file
- copied the legacy server key
- Azure:
- created notification hub
- inserted the legacy server key
- Xamarin Forms App (Android):
- AndroidManifest package name == package name firebase project
- I installed the nuget packages: Xamarin.GooglePlayServices.Base, Xamarin.Firebase.Messaging and Xamarin.Azure.NotificationHubs.Android
- added the google-services.json file to the project and selected the Build Action to GoogleServiceJson
- added the receiver part to the AndroidManifest*
- Then created the classes Constants, MyFirebaseIIDService, MyFirebaseMessagingService and edited the MainActivity
after that the tutorial says "build your project / run your app..." and I get the error.
*here I'm not quite sure what to fill in at ${applicationId}:
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
Thanks for your help!
回答1:
So I'm not quite sure why I got that error. But after updating visual studio from v15.7.1 to v15.7.2 the error was gone. It could be, that a restart of visual studio was the solution? In the tutorial it say's you have to restart vs if you can't select the Build Action "GoogleServiceJson". Perhaps you have to restart it anyway.
For android:name="${applicationId}" I used the same as in "package" out of the "manifest" line in the AndroidManifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="3" android:versionName="1.2" package="com.xxxxx.ServiceToolStandard" android:installLocation="auto">
[...]
<application android:label="ServiceToolStandard" android:icon="@drawable/icon">
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.xxxxx.ServiceToolStandard" />
</intent-filter>
</receiver>
</application>
Now I can build and run the application. Also the push notifications from the Azure-"Test send" are received correctly.
来源:https://stackoverflow.com/questions/50468557/how-to-implement-push-notification-for-xamarin-android