Description
This issue has been moved from a ticket on Developer Community.
[severity:It's more difficult to complete my work]
I have a simple Xamarin.Android .NET 6 app that has API levels set as follows:
<TargetFramework>net6.0-android31</TargetFramework>
<SupportedOSPlatformVersion>26</SupportedOSPlatformVersion>
Its AndroidManifest.xml
file doesn't specify android:minSdkVersion
so in the generated obj\Debug\net6.0-android31\AndroidManifest.xml
is this:
<uses-sdk android:minSdkVersion="26" android:targetSdkVersion="31" />
I have an adaptive icon in Resources\mipmap-anydpi
but when I build I get the following error:
APT2000: <adaptive-icon> elements require a sdk version of at least 26.
As a workaround I currently use this in my .csproj
file:
<AndroidAapt2LinkExtraArgs>--min-sdk-version $(SupportedOSPlatformVersion)</AndroidAapt2LinkExtraArgs>
This imo confirms that the min API version is not correctly passed to (at least) the Aapt2Link
task.
Original Comments
Feedback Bot on 12/23/2021, 09:59 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Feedback Bot on 1/3/2022, 08:39 AM:
Thank you for sharing your feedback! Our teams prioritize action on product issues with broad customer impact. See details at: https://docs.microsoft.com/en-us/visualstudio/ide/report-a-problem?view=vs-2019#faq. In case you need answers to common questions or need assisted support, be sure to use https://visualstudio.microsoft.com/vs/support/. We’ll keep you posted on any updates to this feedback.
Jonathan Peppers [MSFT] on 1/3/2022, 09:29 AM:
I wrote a quick test for this scenario:
https://github.com/xamarin/xamarin-android/compare/main…jonathanpeppers:dotnet-adaptiveicon
But it seems to work for me, I get obj\Debug\net6.0-android\android\AndroidManifest.xml
with <uses-sdk android:minSdkVersion="26" android:targetSdkVersion="31" />
Full contents:
<?xml version="1.0" encoding="utf-8"?> <!-- This code was generated by a tool. It was generated from C:\src\xamarin-android\bin\TestDebug\temp\AdaptiveIcon\AndroidManifest.xml Changes to this file may cause incorrect behavior and will be lost if the contents are regenerated. --> <manifest xmlns:android="https://schemas.android.com/apk/res/android" xmlns:tools="https://schemas.android.com/tools" android:versionCode="1" android:versionName="1.0" package="com.xamarin.adaptiveicon"> <uses-sdk android:minSdkVersion="26" android:targetSdkVersion="31" /> <uses-permission android:name="android.permission.INTERNET" /> <application android:label="UnnamedProject" android:name="android.app.Application" android:allowBackup="true" android:icon="@drawable/icon" android:debuggable="true" android:extractNativeLibs="true"> <activity android:icon="@drawable/icon" android:label="UnnamedProject" android:name="com.xamarin.adaptiveicon.MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="1999999999" android:authorities="com.xamarin.adaptiveicon.mono.MonoRuntimeProvider.__mono_init__" /> </application> </manifest>
Do you have a <uses-sdk/>
element in your AndroidManifest.xml
? You can remove it if you are using $(SupportedOSPlatformVersion)
instead.
Can you attach a diagnostic MSBuild log when you this this issue?
I think we need to see the version of the Android workload, and maybe if there is something else in your project causing this. Thanks!
Why do we ask for more info?
We try to reproduce all issues reported with the information provided in the description and comments. When we can’t reproduce the issue, we ask you for more information so we can resolve the issue as quickly and efficiently as possible.
In our guidelines, you can get tips on how to provide clear and simple reproducible steps.
Marian Dolinský on 1/8/2022, 05:14 PM:
I don’t know how to get the workload version but I ran dotnet workload update
then opened VS, cleaned and rebuilt a few days ago but got the same result 😕
But the problem doesn’t seem to be in the AndroidManifest.xml
generation. The file is generated correctly. Original (in my project) doesn’t have the <uses-sdk/>
tag and the generated does. Only the adaptive icon resource is not processed correctly.
There’s one difference in the test though. I believe it would fail if you change this line
new AndroidItem.AndroidResource("Resources\\mipmap-anydpi-v26\\adaptiveicon.xml")
to be like this:
new AndroidItem.AndroidResource("Resources\\mipmap-anydpi\\adaptiveicon.xml")
That’s how I have it in my project. Since the min SDK of my app is higher than 26 I removed the v26
suffix in the folder name and that’s why it doesn’t build.
Feedback Bot on 1/19/2022, 01:19 PM:
Thank you for sharing your feedback! Our teams prioritize action on product issues with broad customer impact. See details at: https://docs.microsoft.com/en-us/visualstudio/ide/report-a-problem?view=vs-2019#faq. In case you need answers to common questions or need assisted support, be sure to use https://visualstudio.microsoft.com/vs/support/. We’ll keep you posted on any updates to this feedback.
Instructions for AIs
Any MSBuild task that calls aapt2
needs to pass --min-sdk-version
.
Reviewing <D8/>
we pass in AndroidManifestFile="$(IntermediateOutputPath)android\AndroidManifest.xml"
.
So, we can do something like this in any aapt2-related MSBuild task:
//NOTE: if this is blank, we can omit --min-api in this call
if (AndroidManifestFile is { Length: > 0 }) {
var doc = AndroidAppManifest.Load (AndroidManifestFile, MonoAndroidHelper.SupportedVersions);
if (doc.MinSdkVersion.HasValue) {
cmd.AppendSwitchIfNotNull ("--min-sdk-version", doc.MinSdkVersion.Value.ToString ());
}
}