Skip to content
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

[Xamarin.Android.Build.Tasks] Fix Android Version Code for Release builds #7795

Merged
merged 4 commits into from
Mar 27, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<_AndroidPackage>$(ApplicationId)</_AndroidPackage>
<_ApplicationLabel>$(ApplicationTitle)</_ApplicationLabel>
<_AndroidVersionName>$(ApplicationDisplayVersion)</_AndroidVersionName>
<_AndroidVersionCode Condition=" '$(AndroidCreatePackagePerAbi)' != 'true' ">$(ApplicationVersion)</_AndroidVersionCode>
<_AndroidVersionCode>$(ApplicationVersion)</_AndroidVersionCode>
</PropertyGroup>
<AndroidError Code="XA1018"
ResourceName="XA1018"
Expand Down