Skip to content

Fix Aapt2Link not passing min SDK version to aapt2 #10194

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

Merged
merged 13 commits into from
Aug 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

## Critical Rules

Reference official Android documentation where helpful:
* [Android Developer Guide](https://developer.android.com/develop)
* [Android API Reference](https://developer.android.com/reference)
* [Android `aapt2` Documentation](https://developer.android.com/tools/aapt2)

**Only modify the main English `*.resx` files** (e.g., `Resources.resx`)

**Never modify non-English localization files:** `*.lcl` files in `Localize/loc/` or non-English `*.resx` files are auto-generated.
Expand Down Expand Up @@ -149,19 +154,6 @@ try {
- **MSBuild Errors:** `XA####` (errors), `XA####` (warnings), `APT####` (Android tools)
- **Logging:** Use `Log.LogError`, `Log.LogWarning` with error codes and context

## Commit Format
```
[Component] Summary
```
Components: `[Mono.Android]`, `[Build.Tasks]`, `build`, `ci`, `docs`, `tests`

```
Bump to org/repo/branch@commit
Bump to [Dependency Name] [Dependency Version]
```

Required sections: **Changes**, **Fixes** (#issue-numbers), **Context**

## Troubleshooting
- **Build:** Clean `bin/`+`obj/`, check Android SDK/NDK, `make clean`
- **MSBuild:** Test in isolation, validate inputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
JavaPlatformJarPath="$(JavaPlatformJarPath)"
JavaDesignerOutputDirectory="$(ResgenTemporaryDirectory)"
CompiledResourceFlatFiles="@(_CompiledFlatFiles)"
AndroidManifestFile="$(_AndroidManifestAbs)"
ManifestFiles="$(ResgenTemporaryDirectory)\AndroidManifest.xml"
AdditionalAndroidResourcePaths="@(_LibraryResourceDirectories)"
YieldDuringToolExecution="$(YieldDuringToolExecution)"
Expand Down
9 changes: 9 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Tasks/Aapt2Link.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,15 @@ string [] GenerateCommandLineCommands (string ManifestFile, string? currentAbi,
cmd.Add ("-o");
cmd.Add (GetFullPath (currentResourceOutputFile));

// Add min SDK version from AndroidManifestFile if available
if (AndroidManifestFile is { ItemSpec.Length: > 0 }) {
var doc = AndroidAppManifest.Load (AndroidManifestFile.ItemSpec, MonoAndroidHelper.SupportedVersions);
if (doc.MinSdkVersion.HasValue) {
cmd.Add ("--min-sdk-version");
cmd.Add (doc.MinSdkVersion.Value.ToString ());
}
}

return cmd.ToArray ();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
namespace Xamarin.Android.Build.Tests {
[TestFixture]
[Parallelizable (ParallelScope.Self)]
public class AndroidResourceTests : BaseTest {
public class AndroidResourceTests : BaseTest
{
[Test]
public void RTxtParserTest ()
{
Expand Down Expand Up @@ -154,5 +155,32 @@ public void UserLayout ()
Assert.True (mainText.Contains ("FixedWidth"), "'FixedWidth' was converted to 'fixedwidth'");
Directory.Delete (path, recursive: true);
}

[Test]
public void AdaptiveIcon ()
{
var proj = new XamarinAndroidApplicationProject {
SupportedOSPlatformVersion = "26",
AndroidResources = {
new AndroidItem.AndroidResource ("Resources\\mipmap-anydpi-v26\\adaptiveicon.xml") {
TextContent = () => """
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/AdaptiveIcon_background" />
<foreground android:drawable="@mipmap/AdaptiveIcon_foreground" />
</adaptive-icon>
""",
},
new AndroidItem.AndroidResource ("Resources\\mipmap-mdpi\\AdaptiveIcon_background.png") {
BinaryContent = () => XamarinAndroidCommonProject.icon_binary_mdpi,
},
new AndroidItem.AndroidResource ("Resources\\mipmap-mdpi\\AdaptiveIcon_foreground.png") {
BinaryContent = () => XamarinAndroidCommonProject.icon_binary_mdpi,
},
}
};

using var b = CreateApkBuilder ();
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
}
}
}