Skip to content

Commit 64e69a8

Browse files
committed
Parametrize zip alignment
Default to 16 for now, to see which tests (if any) fail
1 parent 91effd3 commit 64e69a8

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@
4545

4646
<!-- Mono components -->
4747
<AndroidEnableProfiler Condition=" '$(AndroidEnableProfiler)' == ''">false</AndroidEnableProfiler>
48+
49+
<!--
50+
Android package (apt/aab) alignment, expressed as the page size in kilobytes. Two values are supported: 4 and 16.
51+
Sometime next year the default value should be changed to 16 since it's going to be a Google Play store requirement for
52+
application submissions
53+
-->
54+
<_AndroidZipAlignment Condition=" '$(_AndroidZipAlignment)' == '' ">16</_AndroidZipAlignment>
4855
</PropertyGroup>
4956

5057
<!-- User-facing configuration-specific defaults -->

src/Xamarin.Android.Build.Tasks/Tasks/AndroidZipAlign.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ namespace Xamarin.Android.Tasks
77
{
88
public class AndroidZipAlign : AndroidRunToolTask
99
{
10+
// Sometime next year the default value should be changed to 16 since it's going to be a Google Play store requirement for
11+
// application submissions
12+
internal const int DefaultZipAlignment = 4;
13+
1014
public override string TaskPrefix => "AZA";
1115

1216
[Required]
@@ -15,7 +19,7 @@ public class AndroidZipAlign : AndroidRunToolTask
1519
[Required]
1620
public ITaskItem DestinationDirectory { get; set; }
1721

18-
int alignment = 4;
22+
int alignment = DefaultZipAlignment;
1923
public int Alignment {
2024
get {return alignment;}
2125
set {alignment = value;}
@@ -53,4 +57,3 @@ protected override void LogEventsFromTextOutput (string singleLine, MessageImpor
5357
}
5458
}
5559
}
56-

src/Xamarin.Android.Build.Tasks/Tasks/GeneratePackageManagerJava.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public class GeneratePackageManagerJava : AndroidTask
8080
public string AndroidSequencePointsMode { get; set; }
8181
public bool EnableSGenConcurrent { get; set; }
8282
public string? CustomBundleConfigFile { get; set; }
83+
public int ZipAlignmentPages { get; set; } = 0;
8384

8485
[Output]
8586
public string BuildId { get; set; }
@@ -334,6 +335,13 @@ void AddEnvironment ()
334335

335336
bool haveRuntimeConfigBlob = !String.IsNullOrEmpty (RuntimeConfigBinFilePath) && File.Exists (RuntimeConfigBinFilePath);
336337
var jniRemappingNativeCodeInfo = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<GenerateJniRemappingNativeCode.JniRemappingNativeCodeInfo> (ProjectSpecificTaskObjectKey (GenerateJniRemappingNativeCode.JniRemappingNativeCodeInfoKey), RegisteredTaskObjectLifetime.Build);
338+
int zipAlignment = ZipAlignmentPages != 0 ? ZipAlignmentPages : AndroidZipAlign.DefaultZipAlignment;
339+
uint zipAlignmentMask = zipAlignment switch {
340+
4 => 3,
341+
16 => 15,
342+
_ => throw new InvalidOperationException ($"Internal error: unsupported zip page alignment value {ZipAlignmentPages}")
343+
};
344+
337345
var appConfigAsmGen = new ApplicationConfigNativeAssemblyGenerator (environmentVariables, systemProperties, Log) {
338346
UsesMonoAOT = usesMonoAOT,
339347
UsesMonoLLVM = EnableLLVM,
@@ -357,7 +365,7 @@ void AddEnvironment ()
357365
JNIEnvRegisterJniNativesToken = jnienv_registerjninatives_method_token,
358366
JniRemappingReplacementTypeCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementTypeCount,
359367
JniRemappingReplacementMethodIndexEntryCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementMethodIndexEntryCount,
360-
ZipAlignmentMask = 3, // TODO: parametrize via Task arguments
368+
ZipAlignmentMask = zipAlignmentMask,
361369
MarshalMethodsEnabled = EnableMarshalMethods,
362370
IgnoreSplitConfigs = ShouldIgnoreSplitConfigs (),
363371
};

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,7 @@ because xbuild doesn't support framework reference assemblies.
17241724
UseAssemblyStore="$(AndroidUseAssemblyStore)"
17251725
EnableMarshalMethods="$(_AndroidUseMarshalMethods)"
17261726
CustomBundleConfigFile="$(AndroidBundleConfigurationFile)"
1727+
ZipAlignmentPages="$(_AndroidZipAlignment)"
17271728
>
17281729
<Output TaskParameter="BuildId" PropertyName="_XamarinBuildId" />
17291730
</GeneratePackageManagerJava>
@@ -2354,7 +2355,8 @@ because xbuild doesn't support framework reference assemblies.
23542355
<Delete Files="%(ApkAbiFilesSigned.FullPath)" Condition=" '$(AndroidUseApkSigner)' == 'true' "/>
23552356
<AndroidZipAlign Condition=" '$(AndroidUseApkSigner)' == 'true' "
23562357
Source="%(ApkAbiFilesIntermediate.Identity)"
2357-
DestinationDirectory="$(OutDir)"
2358+
Alignment="$(_AndroidZipAlignment)"
2359+
DestinationDirectory="$(OutDir)"
23582360
ToolPath="$(ZipAlignToolPath)"
23592361
ToolExe="$(ZipalignToolExe)"
23602362
/>
@@ -2389,7 +2391,8 @@ because xbuild doesn't support framework reference assemblies.
23892391
<Message Text="Unaligned android package '%(ApkAbiFilesUnaligned.FullPath)'" Condition=" '$(AndroidUseApkSigner)' != 'True' And '$(AndroidPackageFormat)' != 'aab' "/>
23902392
<AndroidZipAlign Condition=" '$(AndroidUseApkSigner)' != 'True' And '$(AndroidPackageFormat)' != 'aab' "
23912393
Source="%(ApkAbiFilesUnaligned.Identity)"
2392-
DestinationDirectory="$(OutDir)"
2394+
Alignment="$(_AndroidZipAlignment)"
2395+
DestinationDirectory="$(OutDir)"
23932396
ToolPath="$(ZipAlignToolPath)"
23942397
ToolExe="$(ZipalignToolExe)"
23952398
/>

src/native/xamarin-app-stub/application_dso_stub.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const ApplicationConfig application_config = {
6666
.jnienv_registerjninatives_method_token = 3,
6767
.jni_remapping_replacement_type_count = 2,
6868
.jni_remapping_replacement_method_index_entry_count = 2,
69-
.zip_alignment_mask = 4,
69+
.zip_alignment_mask = 3,
7070
.mono_components_mask = MonoComponent::None,
7171
.android_package_name = android_package_name,
7272
};

0 commit comments

Comments
 (0)