Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot merge Android Manifest elements from class library #8262

Open
hansmbakker opened this issue Aug 10, 2023 · 9 comments · May be fixed by #8273
Open

Cannot merge Android Manifest elements from class library #8262

hansmbakker opened this issue Aug 10, 2023 · 9 comments · May be fixed by #8273
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. enhancement Proposed change to current functionality.

Comments

@hansmbakker
Copy link

hansmbakker commented Aug 10, 2023

Android application type

.NET Android (net7.0-android, etc.)

Affected platform version

VS 2022 17.8 Pre 1, .NET 8 preview 7

Description

I want to create a Maui class library that uses content provider queries to get data from another application.

For this, it is required to add the queries element to the Android Manifest.

I want to automatically add the required element to the Android Manifest of the application project that consumes my library so that it works without manually modifying the Android manifest of that application.

I tried doing this using <AndroidManifestOverlay Include="somefile.xml" /> .

Steps to Reproduce

  1. Create .NET Maui App project
  2. Create .NET Maui class library and add an xml file QueriesPackageRegistration.xml with these contents:
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
      <queries>
        <package android:name="com.companyname.someappid" />
      </queries>
    </manifest>
  3. Add <AndroidManifestOverlay Include="QueriesPackageRegistration.xml" /> to the class library project file
  4. Try adding <AndroidManifestMerger>manifestmerger.jar</AndroidManifestMerger> - no ideas whether this is still needed in xamarin-android 13?
  5. Add a dependency on the class library to the App project
  6. Deploy the app
  7. See that the queries element is not output to the generated Android Manifest.

Did you find any workaround?

No response

Relevant log output

No response

@hansmbakker hansmbakker added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels Aug 10, 2023
@hansmbakker
Copy link
Author

I found somebody write on StackOverflow that

It appears that the manifestmerger is not able to merge the AndroidManifest.xml from multiple projects in the Android solution.

@jonathanpeppers
Copy link
Member

Android class libraries do not contain an AndroidManifest.xml, as there is no mechanism to bundle and redistribute it. There isn't an MSBuild item group for the file type, etc.

However, what you could probably do for now as a workaround:

  1. Make an .aar file -- it is just a .zip file with the extension renamed.
  2. Put your AndroidManifest.xml in the root of the archive
  3. Put the .aar file in your project directory (next to .csproj) file

We do have a way for .aar files to flow from class libraries to application projects. They also happen to support AndroidManifest.xml files.

/cc @dellis1972 if you have other ideas here.

@jonathanpeppers jonathanpeppers added enhancement Proposed change to current functionality. and removed needs-triage Issues that need to be assigned. labels Aug 10, 2023
@jonathanpeppers jonathanpeppers added this to the Under Consideration milestone Aug 10, 2023
@dellis1972
Copy link
Contributor

The AndroidManifestOverlay will only work in the app project. The suggestion about packaging te file into an .aar "should" work.
We do have a way of packaging android resources into an aar for a clas library I think, so maybe just flagging it with AndroidManifest in the class library will work. If it doesn't we should probably add that as an option.

@hansmbakker
Copy link
Author

Thank you both for the ideas! I'll try it early next week and share the outcome here.

@hansmbakker
Copy link
Author

hansmbakker commented Aug 14, 2023

@jonathanpeppers @dellis1972

Outcomes:

  • [Not working] Add AndroidManifest as .xml file to class library. Steps:
    • Add <AndroidManifest>Platforms\Android\AndroidManifest.xml</AndroidManifest> to the first <PropertyGroup> in the csproj file
    • Add Platforms\Android\AndroidManifest.xml containing
      <?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android">
        <queries>
          <package android:name="<somePackageName-intentionally-removed>" />
        </queries>
      </manifest>
  • [Not working] Add AndroidManifest as .aar file to class library. Steps:
    1. Zipped the AndroidManifest.xml so that it is in the root of the zip
    2. Renamed the zip to SomeAndroidManifestAdditions.aar
    3. Put the .aar file in the project directory (next to .csproj) file

I verified both approaches by checking whether the contents of the AndroidManifest I wanted to merge ended up in ConsumingAppProjectDir\obj\Debug\net8.0-android\AndroidManifest.xml

Am I missing something?

Regarding

We do have a way for .aar files to flow from class libraries to application projects.

Should this be picked up automatically?

dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Aug 14, 2023
…from class library

Fixes xamarin#8262

So if a user wants to distribute an AndroidManifest.xml file along with
a NuGet the file is currently NOT included in the library .aar file.
So lets include it if one is present. This will allow NuGet authors
to set default permissions if need be by simply adding the file to the
project directory.

This also fixes an issue in GenerateLibraryResources where if a manifest
file does NOT have a package name.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Aug 14, 2023
…from class library

Fixes xamarin#8262

So if a user wants to distribute an AndroidManifest.xml file along with
a NuGet the file is currently NOT included in the library .aar file.
So lets include it if one is present. This will allow NuGet authors
to set default permissions if need be by simply adding the file to the
project directory.

This also fixes an issue in GenerateLibraryResources where if a manifest
file does NOT have a package name.
@dellis1972
Copy link
Contributor

Fix is up #8273.

@hansmbakker
Copy link
Author

Wow! This must be one of the fastest fixes I've seen here! Thank you very much!

dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Aug 16, 2023
…from class library

Fixes xamarin#8262

So if a user wants to distribute an AndroidManifest.xml file along with
a NuGet the file is currently NOT included in the library .aar file.
So lets include it if one is present. This will allow NuGet authors
to set default permissions if need be by simply adding the file to the
project directory.

This also fixes an issue in GenerateLibraryResources where if a manifest
file does NOT have a package name.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Aug 21, 2023
…from class library

Fixes xamarin#8262

So if a user wants to distribute an AndroidManifest.xml file along with
a NuGet the file is currently NOT included in the library .aar file.
So lets include it if one is present. This will allow NuGet authors
to set default permissions if need be by simply adding the file to the
project directory.

This also fixes an issue in GenerateLibraryResources where if a manifest
file does NOT have a package name.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Oct 3, 2023
…from class library

Fixes xamarin#8262

So if a user wants to distribute an AndroidManifest.xml file along with
a NuGet the file is currently NOT included in the library .aar file.
So lets include it if one is present. This will allow NuGet authors
to set default permissions if need be by simply adding the file to the
project directory.

This also fixes an issue in GenerateLibraryResources where if a manifest
file does NOT have a package name.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Oct 3, 2023
…from class library

Fixes xamarin#8262

So if a user wants to distribute an AndroidManifest.xml file along with
a NuGet the file is currently NOT included in the library .aar file.
So lets include it if one is present. This will allow NuGet authors
to set default permissions if need be by simply adding the file to the
project directory.

This also fixes an issue in GenerateLibraryResources where if a manifest
file does NOT have a package name.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Oct 6, 2023
…from class library

Fixes xamarin#8262

So if a user wants to distribute an AndroidManifest.xml file along with
a NuGet the file is currently NOT included in the library .aar file.
So lets include it if one is present. This will allow NuGet authors
to set default permissions if need be by simply adding the file to the
project directory.

This also fixes an issue in GenerateLibraryResources where if a manifest
file does NOT have a package name.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Oct 10, 2023
…from class library

Fixes xamarin#8262

So if a user wants to distribute an AndroidManifest.xml file along with
a NuGet the file is currently NOT included in the library .aar file.
So lets include it if one is present. This will allow NuGet authors
to set default permissions if need be by simply adding the file to the
project directory.

This also fixes an issue in GenerateLibraryResources where if a manifest
file does NOT have a package name.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Oct 11, 2023
…from class library

Fixes xamarin#8262

So if a user wants to distribute an AndroidManifest.xml file along with
a NuGet the file is currently NOT included in the library .aar file.
So lets include it if one is present. This will allow NuGet authors
to set default permissions if need be by simply adding the file to the
project directory.

This also fixes an issue in GenerateLibraryResources where if a manifest
file does NOT have a package name.
@jpobst
Copy link
Contributor

jpobst commented May 17, 2024

Should be fixed in #8273.

@jpobst jpobst closed this as completed May 17, 2024
@jpobst
Copy link
Contributor

jpobst commented May 17, 2024

My bad, that PR isn't merged.

@jpobst jpobst reopened this May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App+Library Build Issues when building Library projects or Application projects. enhancement Proposed change to current functionality.
Projects
None yet
4 participants