diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.cs index 2e5dcb46203..4559fada920 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.cs @@ -522,6 +522,46 @@ public void VersionCodeTests (bool seperateApk, string abis, string versionCode, } } + [Test] + [TestCase ("1", false, "manifest=1")] + [TestCase ("1", true, "x86_64=500001;arm64-v8a=400001")] + [TestCase ("2", false, "manifest=2")] + [TestCase ("2", true, "x86_64=500002;arm64-v8a=400002")] + [TestCase ("999", false, "manifest=999")] + [TestCase ("999", true, "x86_64=500999;arm64-v8a=400999")] + public void ApplicationVersionTests (string applicationVersion, bool seperateApk, string expected) + { + var proj = new XamarinAndroidApplicationProject () { + IsRelease = true, + MinSdkVersion = null, + }; + proj.SetProperty (proj.ReleaseProperties, "ApplicationVersion", applicationVersion); + proj.SetProperty (proj.ReleaseProperties, "ApplicationDisplayVersion", applicationVersion); + proj.SetProperty (proj.ReleaseProperties, KnownProperties.AndroidCreatePackagePerAbi, seperateApk); + proj.AndroidManifest = proj.AndroidManifest + .Replace ("android:versionCode=\"1\"", string.Empty) + .Replace ("android:versionName=\"1.0\"", string.Empty); + using (var builder = CreateApkBuilder ()) { + Assert.True (builder.Build (proj), "Build should have succeeded."); + XNamespace aNS = "http://schemas.android.com/apk/res/android"; + + var expectedItems = expected.Split (';'); + foreach (var item in expectedItems) { + var items = item.Split ('='); + var path = Path.Combine ("android", items [0], "AndroidManifest.xml"); + var manifest = builder.Output.GetIntermediaryAsText (Root, path); + var doc = XDocument.Parse (manifest); + var m = doc.XPathSelectElement ("/manifest") as XElement; + Assert.IsNotNull (m, "no manifest element found"); + var vc = m.Attribute (aNS + "versionCode"); + Assert.IsNotNull (vc, "no versionCode attribute found"); + StringAssert.AreEqualIgnoringCase (items [1], vc.Value, + $"Version Code is incorrect. Found {vc.Value} expect {items [1]}"); + } + + } + } + [Test] public void ManifestPlaceholders ([Values ("legacy", "manifestmerger.jar")] string manifestMerger) { diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 6c88e3b8958..c642f4507a7 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -599,7 +599,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. <_AndroidPackage>$(ApplicationId) <_ApplicationLabel>$(ApplicationTitle) <_AndroidVersionName>$(ApplicationDisplayVersion) - <_AndroidVersionCode Condition=" '$(AndroidCreatePackagePerAbi)' != 'true' ">$(ApplicationVersion) + <_AndroidVersionCode>$(ApplicationVersion)