@@ -107,6 +107,8 @@ public class BuildApk : AndroidTask
107107
108108 public string ZipFlushSizeLimit { get ; set ; }
109109
110+ public int ZipAlignmentPages { get ; set ; } = AndroidZipAlign . DefaultZipAlignment64Bit ;
111+
110112 [ Required ]
111113 public string ProjectFullPath { get ; set ; }
112114
@@ -683,14 +685,15 @@ sealed class LibInfo
683685 public string Link ;
684686 public string Abi ;
685687 public string ArchiveFileName ;
688+ public ITaskItem Item ;
686689 }
687690
688691 CompressionMethod GetCompressionMethod ( string fileName )
689692 {
690693 return uncompressedFileExtensions . Contains ( Path . GetExtension ( fileName ) ) ? UncompressedMethod : CompressionMethod . Default ;
691694 }
692695
693- void AddNativeLibraryToArchive ( ZipArchiveEx apk , string abi , string filesystemPath , string inArchiveFileName )
696+ void AddNativeLibraryToArchive ( ZipArchiveEx apk , string abi , string filesystemPath , string inArchiveFileName , ITaskItem taskItem )
694697 {
695698 string archivePath = MakeArchiveLibPath ( abi , inArchiveFileName ) ;
696699 existingEntries . Remove ( archivePath ) ;
@@ -700,6 +703,7 @@ void AddNativeLibraryToArchive (ZipArchiveEx apk, string abi, string filesystemP
700703 return ;
701704 }
702705 Log . LogDebugMessage ( $ "Adding native library: { filesystemPath } (APK path: { archivePath } )") ;
706+ ELFHelper . AssertValidLibraryAlignment ( Log , ZipAlignmentPages , filesystemPath , taskItem ) ;
703707 apk . AddEntryAndFlush ( archivePath , File . OpenRead ( filesystemPath ) , compressionMethod ) ;
704708 }
705709
@@ -709,7 +713,7 @@ void AddRuntimeLibraries (ZipArchiveEx apk, string [] supportedAbis)
709713 foreach ( ITaskItem item in ApplicationSharedLibraries ) {
710714 if ( String . Compare ( abi , item . GetMetadata ( "abi" ) , StringComparison . Ordinal ) != 0 )
711715 continue ;
712- AddNativeLibraryToArchive ( apk , abi , item . ItemSpec , Path . GetFileName ( item . ItemSpec ) ) ;
716+ AddNativeLibraryToArchive ( apk , abi , item . ItemSpec , Path . GetFileName ( item . ItemSpec ) , item ) ;
713717 }
714718 }
715719 }
@@ -762,7 +766,8 @@ private void AddNativeLibraries (ArchiveFileList files, string [] supportedAbis)
762766 Path = v . ItemSpec ,
763767 Link = v . GetMetadata ( "Link" ) ,
764768 Abi = GetNativeLibraryAbi ( v ) ,
765- ArchiveFileName = GetArchiveFileName ( v )
769+ ArchiveFileName = GetArchiveFileName ( v ) ,
770+ Item = v ,
766771 } ) ;
767772
768773 AddNativeLibraries ( files , supportedAbis , frameworkLibs ) ;
@@ -773,7 +778,8 @@ private void AddNativeLibraries (ArchiveFileList files, string [] supportedAbis)
773778 Path = v . ItemSpec ,
774779 Link = v . GetMetadata ( "Link" ) ,
775780 Abi = GetNativeLibraryAbi ( v ) ,
776- ArchiveFileName = GetArchiveFileName ( v )
781+ ArchiveFileName = GetArchiveFileName ( v ) ,
782+ Item = v ,
777783 }
778784 ) ;
779785
@@ -854,8 +860,9 @@ void AddNativeLibraries (ArchiveFileList files, string [] supportedAbis, System.
854860 string . Join ( ", " , libs . Where ( lib => lib . Abi == null ) . Select ( lib => lib . Path ) ) ) ;
855861 libs = libs . Where ( lib => lib . Abi != null ) ;
856862 libs = libs . Where ( lib => supportedAbis . Contains ( lib . Abi ) ) ;
857- foreach ( var info in libs )
858- AddNativeLibrary ( files , info . Path , info . Abi , info . ArchiveFileName ) ;
863+ foreach ( var info in libs ) {
864+ AddNativeLibrary ( files , info . Path , info . Abi , info . ArchiveFileName , info . Item ) ;
865+ }
859866 }
860867
861868 private void AddAdditionalNativeLibraries ( ArchiveFileList files , string [ ] supportedAbis )
@@ -868,12 +875,13 @@ private void AddAdditionalNativeLibraries (ArchiveFileList files, string [] supp
868875 Path = l . ItemSpec ,
869876 Abi = AndroidRidAbiHelper . GetNativeLibraryAbi ( l ) ,
870877 ArchiveFileName = l . GetMetadata ( "ArchiveFileName" ) ,
878+ Item = l ,
871879 } ) ;
872880
873881 AddNativeLibraries ( files , supportedAbis , libs ) ;
874882 }
875883
876- void AddNativeLibrary ( ArchiveFileList files , string path , string abi , string archiveFileName )
884+ void AddNativeLibrary ( ArchiveFileList files , string path , string abi , string archiveFileName , ITaskItem ? taskItem = null )
877885 {
878886 string fileName = string . IsNullOrEmpty ( archiveFileName ) ? Path . GetFileName ( path ) : archiveFileName ;
879887 var item = ( filePath : path , archivePath : MakeArchiveLibPath ( abi , fileName ) ) ;
@@ -882,6 +890,7 @@ void AddNativeLibrary (ArchiveFileList files, string path, string abi, string ar
882890 return ;
883891 }
884892
893+ ELFHelper . AssertValidLibraryAlignment ( Log , ZipAlignmentPages , path , taskItem ) ;
885894 if ( ! ELFHelper . IsEmptyAOTLibrary ( Log , item . filePath ) ) {
886895 files . Add ( item ) ;
887896 } else {
0 commit comments