Xamarin Android AndroidManifest.xml 3rd party package merge - service name class namespace

Markus Jessl 21 Reputation points
2021-12-14T07:48:25.29+00:00

Hello,

I'm currently updating my Xamarin Android project to be fully Android 12 compliant.

I use a 3rd party package which in it's own manifest has a service (with intent-filter) defined but misses the mandatory android:exported settings which are mandatory for Android 12.
This 3rd party package might not get updated soon from its developers.

The original 3rd party class starts like this:

namespace Plugin.FirebasePushNotification
{
    [Service]
    [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
    public class PNFirebaseMessagingService : FirebaseMessagingService
    {

As you can see the mandatory android:exported related setting is missing.

I could overcome the problem by merging the android:exported settings inside my Xamarin Android AndroidManifest.xml file.

<!-- Necessary for Plugin.FirebasePushNotification -->
<service android:name="crc6494e14b9856016c30.PNFirebaseMessagingService" android:exported="false" tools:node="merge">
  <intent-filter>
    <action android:name="com.google.firebase.MESSAGING_EVENT" />
  </intent-filter>
</service>

However, I have no idea why Visual Studio 2019 (latest version) is generating the namespace crc6494e14b9856016c30 for the 3rd party class during the merge (instead of the original namespace Plugin.FirebasePushNotification).
I would prefer not to hard code crc6494e14b9856016c30 in my Xamarin Android AndroidManifest.xml file as this namespace is something the merger generated and it might change in the future.

Is there a way to to get the namespace from the merger dynamically and just use a variable or something else in my Xamarin Android AndroidManifest.xml file settings?

Thx a lot.

Developer technologies | .NET | Xamarin

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.