Skip to content

Commit 84c2911

Browse files
committed
Only conditionally include <uses-sdk /> in the AndroidManifest.xml when saving
Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1874249
1 parent ed102fc commit 84c2911

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Xamarin.Android.Tools.AndroidSdk/AndroidAppManifest.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Linq;
33
using System.Xml;
44
using System.Collections.Generic;
@@ -45,7 +45,7 @@ public class AndroidAppManifest
4545
if (manifest.Element ("uses-sdk") is XElement uses)
4646
usesSdk = uses;
4747
else
48-
manifest.Add (usesSdk = new XElement ("uses-sdk"));
48+
usesSdk = new XElement ("uses-sdk");
4949
}
5050

5151
public static string CanonicalizePackageName (string packageNameOrAssemblyName)
@@ -71,7 +71,6 @@ public static AndroidAppManifest Create (string packageName, string appLabel, An
7171
return new AndroidAppManifest (versions, XDocument.Parse (
7272
@"<?xml version=""1.0"" encoding=""utf-8""?>
7373
<manifest xmlns:android=""http://schemas.android.com/apk/res/android"" android:versionCode=""1"" android:versionName=""1.0"">
74-
<uses-sdk />
7574
<application android:label="""">
7675
</application>
7776
</manifest>")) {
@@ -102,6 +101,14 @@ public static AndroidAppManifest Load (XDocument doc, AndroidVersions versions)
102101

103102
public void Write (XmlWriter writer)
104103
{
104+
// Make sure that if the <uses-sdk /> XML element does not have any attributes (i.e. minSdkVersion
105+
// and targetSdkVersion), do NOT write it into the output. This is to avoid issues like
106+
// https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1874249/
107+
if (usesSdk.HasAttributes && usesSdk.Parent == null)
108+
manifest.Add (usesSdk);
109+
else if (!usesSdk.HasAttributes && usesSdk.Parent != null)
110+
usesSdk.Remove ();
111+
105112
doc.Save (writer);
106113
}
107114

0 commit comments

Comments
 (0)