MSBuild 16.0 inserts empty uses-sdk element into AndroidManifest.xml

Katsuhiro Mihara 41 Reputation points
2022-12-16T10:30:28.247+00:00

I build C# assembles and a Xamarin.Forms application for Android. One of C# assemble refers JARs for Android. I build these by MSBuild 16.0.

MSBuild 16.0 inserts empty uses-sdk element into AndroidManifest.xml of a C# assemble that refers JARs. So, while building the application, MSBuild recognizes minSdkVersion of the assemble as "1" and raises build errors.

I want to stop inserting empty uses-sdk element or control minSdkVersion manually. How to do these?

---
Environment

Visual Studio Professional 2022 for Mac
Version 17.4.1 (build 28)

Runtime
.NET 6.0.9 (64-bit)
Architecture: X64

Roslyn (Language Service)
4. 4.0-6.22578.12+3c6ab8e1715e5b080fb7bb77070810ab71e09387

.NET SDK (x64)
SDK: /usr/local/share/dotnet/sdk/7.0.100/Sdks
SDK version:
7.0.100
6.0.403
MSBuild SDK: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks

.NET runtime (x64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime version:
7.0.0
6.0.11

Xamarin.Android
Version: 13.1.0.1 (Visual Studio Professional)
Commit :xamarin-android/d17-4/13ba222
Android SDK: /Users/katsuhiro.mihara/Library/Android/sdk
Android version:
12.0 (API level 31)
11.0 (API level 30)
10.0 (API level 29)
9.0 (API level 28)
13.0 (API level 33)

Operating System
Mac OS X 13.0.0
Darwin 22.1.0 Darwin Kernel Version 22.1.0
Sun Oct 9 20:14:54 PDT 2022
root:xnu-8792.41.9~2/RELEASE_X86_64 x86_64

(Original text is Japanese)

Developer technologies .NET Xamarin
Community Center Not monitored
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2022-12-19T07:42:57.507+00:00

    Hello,

    It should be caused by you didn't declare minSdkVersion of the <uses-sdk> tag.

    You could refer to <uses-sdk>, and find the following remark:

    Caution: If you do not declare this attribute, the system assumes a default value of "1", which indicates that your application is compatible with all versions of Android. If your application is not compatible with all versions (for instance, it uses APIs introduced in API Level 3) and you have not declared the proper minSdkVersion, then when installed on a system with an API Level less than 3, the application will crash during runtime when attempting to access the unavailable APIs. For this reason, be certain to declare the appropriate API Level in the minSdkVersion attribute.animation.

    Therefore, you could try to add <uses-sdk android:minSdkVersion="int"> into your AndroidManifest file.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

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