Skip to content

Commit

Permalink
Parametrize zip alignment
Browse files Browse the repository at this point in the history
Default to 16 for now, to see which tests (if any) fail
  • Loading branch information
grendello committed Jun 18, 2024
1 parent 91effd3 commit 64e69a8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@

<!-- Mono components -->
<AndroidEnableProfiler Condition=" '$(AndroidEnableProfiler)' == ''">false</AndroidEnableProfiler>

<!--
Android package (apt/aab) alignment, expressed as the page size in kilobytes. Two values are supported: 4 and 16.
Sometime next year the default value should be changed to 16 since it's going to be a Google Play store requirement for
application submissions
-->
<_AndroidZipAlignment Condition=" '$(_AndroidZipAlignment)' == '' ">16</_AndroidZipAlignment>
</PropertyGroup>

<!-- User-facing configuration-specific defaults -->
Expand Down
7 changes: 5 additions & 2 deletions src/Xamarin.Android.Build.Tasks/Tasks/AndroidZipAlign.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ namespace Xamarin.Android.Tasks
{
public class AndroidZipAlign : AndroidRunToolTask
{
// Sometime next year the default value should be changed to 16 since it's going to be a Google Play store requirement for
// application submissions
internal const int DefaultZipAlignment = 4;

public override string TaskPrefix => "AZA";

[Required]
Expand All @@ -15,7 +19,7 @@ public class AndroidZipAlign : AndroidRunToolTask
[Required]
public ITaskItem DestinationDirectory { get; set; }

int alignment = 4;
int alignment = DefaultZipAlignment;
public int Alignment {
get {return alignment;}
set {alignment = value;}
Expand Down Expand Up @@ -53,4 +57,3 @@ protected override void LogEventsFromTextOutput (string singleLine, MessageImpor
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class GeneratePackageManagerJava : AndroidTask
public string AndroidSequencePointsMode { get; set; }
public bool EnableSGenConcurrent { get; set; }
public string? CustomBundleConfigFile { get; set; }
public int ZipAlignmentPages { get; set; } = 0;

[Output]
public string BuildId { get; set; }
Expand Down Expand Up @@ -334,6 +335,13 @@ void AddEnvironment ()

bool haveRuntimeConfigBlob = !String.IsNullOrEmpty (RuntimeConfigBinFilePath) && File.Exists (RuntimeConfigBinFilePath);
var jniRemappingNativeCodeInfo = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<GenerateJniRemappingNativeCode.JniRemappingNativeCodeInfo> (ProjectSpecificTaskObjectKey (GenerateJniRemappingNativeCode.JniRemappingNativeCodeInfoKey), RegisteredTaskObjectLifetime.Build);
int zipAlignment = ZipAlignmentPages != 0 ? ZipAlignmentPages : AndroidZipAlign.DefaultZipAlignment;
uint zipAlignmentMask = zipAlignment switch {
4 => 3,
16 => 15,
_ => throw new InvalidOperationException ($"Internal error: unsupported zip page alignment value {ZipAlignmentPages}")
};

var appConfigAsmGen = new ApplicationConfigNativeAssemblyGenerator (environmentVariables, systemProperties, Log) {
UsesMonoAOT = usesMonoAOT,
UsesMonoLLVM = EnableLLVM,
Expand All @@ -357,7 +365,7 @@ void AddEnvironment ()
JNIEnvRegisterJniNativesToken = jnienv_registerjninatives_method_token,
JniRemappingReplacementTypeCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementTypeCount,
JniRemappingReplacementMethodIndexEntryCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementMethodIndexEntryCount,
ZipAlignmentMask = 3, // TODO: parametrize via Task arguments
ZipAlignmentMask = zipAlignmentMask,
MarshalMethodsEnabled = EnableMarshalMethods,
IgnoreSplitConfigs = ShouldIgnoreSplitConfigs (),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,7 @@ because xbuild doesn't support framework reference assemblies.
UseAssemblyStore="$(AndroidUseAssemblyStore)"
EnableMarshalMethods="$(_AndroidUseMarshalMethods)"
CustomBundleConfigFile="$(AndroidBundleConfigurationFile)"
ZipAlignmentPages="$(_AndroidZipAlignment)"
>
<Output TaskParameter="BuildId" PropertyName="_XamarinBuildId" />
</GeneratePackageManagerJava>
Expand Down Expand Up @@ -2354,7 +2355,8 @@ because xbuild doesn't support framework reference assemblies.
<Delete Files="%(ApkAbiFilesSigned.FullPath)" Condition=" '$(AndroidUseApkSigner)' == 'true' "/>
<AndroidZipAlign Condition=" '$(AndroidUseApkSigner)' == 'true' "
Source="%(ApkAbiFilesIntermediate.Identity)"
DestinationDirectory="$(OutDir)"
Alignment="$(_AndroidZipAlignment)"
DestinationDirectory="$(OutDir)"
ToolPath="$(ZipAlignToolPath)"
ToolExe="$(ZipalignToolExe)"
/>
Expand Down Expand Up @@ -2389,7 +2391,8 @@ because xbuild doesn't support framework reference assemblies.
<Message Text="Unaligned android package '%(ApkAbiFilesUnaligned.FullPath)'" Condition=" '$(AndroidUseApkSigner)' != 'True' And '$(AndroidPackageFormat)' != 'aab' "/>
<AndroidZipAlign Condition=" '$(AndroidUseApkSigner)' != 'True' And '$(AndroidPackageFormat)' != 'aab' "
Source="%(ApkAbiFilesUnaligned.Identity)"
DestinationDirectory="$(OutDir)"
Alignment="$(_AndroidZipAlignment)"
DestinationDirectory="$(OutDir)"
ToolPath="$(ZipAlignToolPath)"
ToolExe="$(ZipalignToolExe)"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/native/xamarin-app-stub/application_dso_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const ApplicationConfig application_config = {
.jnienv_registerjninatives_method_token = 3,
.jni_remapping_replacement_type_count = 2,
.jni_remapping_replacement_method_index_entry_count = 2,
.zip_alignment_mask = 4,
.zip_alignment_mask = 3,
.mono_components_mask = MonoComponent::None,
.android_package_name = android_package_name,
};
Expand Down

0 comments on commit 64e69a8

Please sign in to comment.