Does Xamarin.Android support Manifest merging?

Emil Alipiev 246 Reputation points
2020-12-01T22:30:48.237+00:00

I have a xamarin.android library project referencing on main xamarin.android project.
So in the xamarin.Android Library project's manifest I defined permissions like below

<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:amazon="http://schemas.amazon.com/apk/res/android" package="com.myapp">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="29" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

In the Main xamarin.android project I dont have those permissions.

What i expect at the end a merge between 2 Manifest files and those permissions defined in the Android library project should be included but when i check the obj\Debug\100 folder where androidmanifest. xaml is created, if i open it, i dont see those permissions.
Is manifest merge not included by default or should I do something?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
4,923 questions
No comments
{count} votes

Accepted answer
  1. Joe Manke 1,091 Reputation points
    2020-12-01T22:59:33.813+00:00

    I don't know about that sort of manifest merging, but if you use the UsesPermission attribute in C# in the library, the permissions should be added to the manifest of the consuming project. Convention is to put them in AssemblyInfo.cs but as it's an assembly-level attribute you can put them in any .cs file.

    [assembly: UsesPermission(Android.Manifest.Permission.Internet)]
    [assembly: UsesPermission(Android.Manifest.Permission.Vibrate)]
    [assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
    [assembly: UsesPermission(Android.Manifest.Permission.ReadExternalStorage)]
    [assembly: UsesPermission(Android.Manifest.Permission.AccessCoarseLocation)]
    [assembly: UsesPermission(Android.Manifest.Permission.AccessFineLocation)]
    
    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Emil Alipiev 246 Reputation points
    2020-12-01T23:06:17.443+00:00

    Actually found the related issue https://github.com/xamarin/xamarin-android/issues/3428
    Something new was implemented but suggestion in the issue is not 100% working for me.
    I have updated the issue with the problem i have experienced

  2. Mel Cvjetko 1 Reputation point
    2021-02-24T14:30:06.453+00:00

    Default Manifest merging was written in C# and is not ideal.

    Ideal world uses ManifestMerger.jar add following codesnippet to app csproj:

    <AndroidManifestMerger>manifestmerger.jar</AndroidManifestMerger>