@@ -107,6 +107,8 @@ public class BuildApk : AndroidTask
107
107
108
108
public string ZipFlushSizeLimit { get ; set ; }
109
109
110
+ public int ZipAlignmentPages { get ; set ; } = AndroidZipAlign . DefaultZipAlignment64Bit ;
111
+
110
112
[ Required ]
111
113
public string ProjectFullPath { get ; set ; }
112
114
@@ -683,14 +685,15 @@ sealed class LibInfo
683
685
public string Link ;
684
686
public string Abi ;
685
687
public string ArchiveFileName ;
688
+ public ITaskItem Item ;
686
689
}
687
690
688
691
CompressionMethod GetCompressionMethod ( string fileName )
689
692
{
690
693
return uncompressedFileExtensions . Contains ( Path . GetExtension ( fileName ) ) ? UncompressedMethod : CompressionMethod . Default ;
691
694
}
692
695
693
- void AddNativeLibraryToArchive ( ZipArchiveEx apk , string abi , string filesystemPath , string inArchiveFileName )
696
+ void AddNativeLibraryToArchive ( ZipArchiveEx apk , string abi , string filesystemPath , string inArchiveFileName , ITaskItem taskItem )
694
697
{
695
698
string archivePath = MakeArchiveLibPath ( abi , inArchiveFileName ) ;
696
699
existingEntries . Remove ( archivePath ) ;
@@ -700,6 +703,7 @@ void AddNativeLibraryToArchive (ZipArchiveEx apk, string abi, string filesystemP
700
703
return ;
701
704
}
702
705
Log . LogDebugMessage ( $ "Adding native library: { filesystemPath } (APK path: { archivePath } )") ;
706
+ ELFHelper . AssertValidLibraryAlignment ( Log , ZipAlignmentPages , filesystemPath , taskItem ) ;
703
707
apk . AddEntryAndFlush ( archivePath , File . OpenRead ( filesystemPath ) , compressionMethod ) ;
704
708
}
705
709
@@ -709,7 +713,7 @@ void AddRuntimeLibraries (ZipArchiveEx apk, string [] supportedAbis)
709
713
foreach ( ITaskItem item in ApplicationSharedLibraries ) {
710
714
if ( String . Compare ( abi , item . GetMetadata ( "abi" ) , StringComparison . Ordinal ) != 0 )
711
715
continue ;
712
- AddNativeLibraryToArchive ( apk , abi , item . ItemSpec , Path . GetFileName ( item . ItemSpec ) ) ;
716
+ AddNativeLibraryToArchive ( apk , abi , item . ItemSpec , Path . GetFileName ( item . ItemSpec ) , item ) ;
713
717
}
714
718
}
715
719
}
@@ -762,7 +766,8 @@ private void AddNativeLibraries (ArchiveFileList files, string [] supportedAbis)
762
766
Path = v . ItemSpec ,
763
767
Link = v . GetMetadata ( "Link" ) ,
764
768
Abi = GetNativeLibraryAbi ( v ) ,
765
- ArchiveFileName = GetArchiveFileName ( v )
769
+ ArchiveFileName = GetArchiveFileName ( v ) ,
770
+ Item = v ,
766
771
} ) ;
767
772
768
773
AddNativeLibraries ( files , supportedAbis , frameworkLibs ) ;
@@ -773,7 +778,8 @@ private void AddNativeLibraries (ArchiveFileList files, string [] supportedAbis)
773
778
Path = v . ItemSpec ,
774
779
Link = v . GetMetadata ( "Link" ) ,
775
780
Abi = GetNativeLibraryAbi ( v ) ,
776
- ArchiveFileName = GetArchiveFileName ( v )
781
+ ArchiveFileName = GetArchiveFileName ( v ) ,
782
+ Item = v ,
777
783
}
778
784
) ;
779
785
@@ -854,8 +860,9 @@ void AddNativeLibraries (ArchiveFileList files, string [] supportedAbis, System.
854
860
string . Join ( ", " , libs . Where ( lib => lib . Abi == null ) . Select ( lib => lib . Path ) ) ) ;
855
861
libs = libs . Where ( lib => lib . Abi != null ) ;
856
862
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
+ }
859
866
}
860
867
861
868
private void AddAdditionalNativeLibraries ( ArchiveFileList files , string [ ] supportedAbis )
@@ -868,12 +875,13 @@ private void AddAdditionalNativeLibraries (ArchiveFileList files, string [] supp
868
875
Path = l . ItemSpec ,
869
876
Abi = AndroidRidAbiHelper . GetNativeLibraryAbi ( l ) ,
870
877
ArchiveFileName = l . GetMetadata ( "ArchiveFileName" ) ,
878
+ Item = l ,
871
879
} ) ;
872
880
873
881
AddNativeLibraries ( files , supportedAbis , libs ) ;
874
882
}
875
883
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 )
877
885
{
878
886
string fileName = string . IsNullOrEmpty ( archiveFileName ) ? Path . GetFileName ( path ) : archiveFileName ;
879
887
var item = ( filePath : path , archivePath : MakeArchiveLibPath ( abi , fileName ) ) ;
@@ -882,6 +890,7 @@ void AddNativeLibrary (ArchiveFileList files, string path, string abi, string ar
882
890
return ;
883
891
}
884
892
893
+ ELFHelper . AssertValidLibraryAlignment ( Log , ZipAlignmentPages , path , taskItem ) ;
885
894
if ( ! ELFHelper . IsEmptyAOTLibrary ( Log , item . filePath ) ) {
886
895
files . Add ( item ) ;
887
896
} else {
0 commit comments