LOCAL_MODULE_TAGS := optional
endif
+ifeq ($(LOCAL_PACKAGE_ALIGNMENT),)
+LOCAL_PACKAGE_ALIGNMENT := $(DEFAULT_PACKAGE_ALIGNMENT)
+endif
+
+ifeq ($(LOCAL_JNI_SHARED_LIBRARIES_PACKAGE_ALIGNMENT),)
+LOCAL_JNI_SHARED_LIBRARIES_PACKAGE_ALIGNMENT := $(DEFAULT_JNI_SHARED_LIBRARIES_PACKAGE_ALIGNMENT)
+endif
+
ifeq ($(filter tests, $(LOCAL_MODULE_TAGS)),)
# Force localization check if it's not tagged as tests.
LOCAL_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) -z
$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis)
# PRIVATE_JNI_SHARED_LIBRARIES_ABI is a list of ABI names.
$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis)
+$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ZIP_OPTIONS := $(LOCAL_JNI_SHARED_LIBRARIES_ZIP_OPTIONS)
+$(LOCAL_BUILT_MODULE): PRIVATE_PAGE_ALIGN_JNI_SHARED_LIBRARIES := $(LOCAL_PAGE_ALIGN_JNI_SHARED_LIBRARIES)
ifneq ($(TARGET_BUILD_APPS),)
# Include all resources for unbundled apps.
LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
@rm -rf $(dir $@) && mkdir -p $(dir $@)
$(hide) cp $< $@
$(hide) zip -d $@ $(foreach f,$(PRIVATE_JNI_SHARED_LIBRARIES),\*/$(f))
- $(call align-package)
+ $(align-package)
$(call dist-for-goals, apps_only, $(apk_jni_stripped):$(dist_subdir)/$(LOCAL_PACKAGE_NAME).apk)
fprintf(stderr, "Zip alignment utility\n");
fprintf(stderr, "Copyright (C) 2009 The Android Open Source Project\n\n");
fprintf(stderr,
- "Usage: zipalign [-f] [-v] [-z] <align> infile.zip outfile.zip\n"
- " zipalign -c [-v] <align> infile.zip\n\n" );
+ "Usage: zipalign [-f] [-p] [-v] [-z] <align> infile.zip outfile.zip\n"
+ " zipalign -c [-v] <align> infile.zip [list of files]\n\n" );
fprintf(stderr,
" <align>: alignment in bytes, e.g. '4' provides 32-bit alignment\n");
fprintf(stderr, " -c: check alignment only (does not modify file)\n");
fprintf(stderr, " -f: overwrite existing outfile.zip\n");
+ fprintf(stderr, " -p: page align stored shared object: files\n");
fprintf(stderr, " -v: verbose output\n");
fprintf(stderr, " -z: recompress using Zopfli\n");
}
+static const int kPageAlignment = 4096;
+
+static int getAlignment(bool pageAlignSharedLibs, int defaultAlignment,
+ ZipEntry* pEntry) {
+
+ if (!pageAlignSharedLibs) {
+ return defaultAlignment;
+ }
+
+ const char* ext = strrchr(pEntry->getFileName(), '.');
+ if (ext && strcmp(ext, ".so") == 0) {
+ return kPageAlignment;
+ }
+
+ return defaultAlignment;
+}
+
/*
* Copy all entries from "pZin" to "pZout", aligning as needed.
*/
-static int copyAndAlign(ZipFile* pZin, ZipFile* pZout, int alignment, bool zopfli)
+static int copyAndAlign(ZipFile* pZin, ZipFile* pZout, int alignment, bool zopfli,
+ bool pageAlignSharedLibs)
{
int numEntries = pZin->getNumEntries();
ZipEntry* pEntry;
status = pZout->add(pZin, pEntry, padding, &pNewEntry);
}
} else {
+ const int alignTo = getAlignment(pageAlignSharedLibs, alignment, pEntry);
+
/*
* Copy the entry, adjusting as required. We assume that the
* file position in the new file will be equal to the file
* position in the original.
*/
long newOffset = pEntry->getFileOffset() + bias;
- padding = (alignment - (newOffset % alignment)) % alignment;
+ padding = (alignTo - (newOffset % alignTo)) % alignTo;
//printf("--- %s: orig at %ld(+%d) len=%ld, adding pad=%d\n",
// pEntry->getFileName(), (long) pEntry->getFileOffset(),
* output file exists and "force" wasn't specified.
*/
static int process(const char* inFileName, const char* outFileName,
- int alignment, bool force, bool zopfli)
+ int alignment, bool force, bool zopfli, bool pageAlignSharedLibs)
{
ZipFile zin, zout;
return 1;
}
- int result = copyAndAlign(&zin, &zout, alignment, zopfli);
+ int result = copyAndAlign(&zin, &zout, alignment, zopfli, pageAlignSharedLibs);
if (result != 0) {
printf("zipalign: failed rewriting '%s' to '%s'\n",
inFileName, outFileName);
/*
* Verify the alignment of a zip archive.
*/
-static int verify(const char* fileName, int alignment, bool verbose)
+static int verify(const char* fileName, int alignment, bool verbose,
+ bool pageAlignSharedLibs)
{
ZipFile zipFile;
bool foundBad = false;
}
} else {
long offset = pEntry->getFileOffset();
- if ((offset % alignment) != 0) {
+ const int alignTo = getAlignment(pageAlignSharedLibs, alignment, pEntry);
+ if ((offset % alignTo) != 0) {
if (verbose) {
printf("%8ld %s (BAD - %ld)\n",
(long) offset, pEntry->getFileName(),
- offset % alignment);
+ offset % alignTo);
}
foundBad = true;
} else {
bool force = false;
bool verbose = false;
bool zopfli = false;
+ bool pageAlignSharedLibs = false;
int result = 1;
int alignment;
char* endp;
case 'z':
zopfli = true;
break;
+ case 'p':
+ pageAlignSharedLibs = true;
+ break;
default:
fprintf(stderr, "ERROR: unknown flag -%c\n", *cp);
wantUsage = true;
if (check) {
/* check existing archive for correct alignment */
- result = verify(argv[1], alignment, verbose);
+ result = verify(argv[1], alignment, verbose, pageAlignSharedLibs);
} else {
/* create the new archive */
- result = process(argv[1], argv[2], alignment, force, zopfli);
+ result = process(argv[1], argv[2], alignment, force, zopfli, pageAlignSharedLibs);
/* trust, but verify */
- if (result == 0)
- result = verify(argv[2], alignment, verbose);
+ if (result == 0) {
+ result = verify(argv[2], alignment, verbose, pageAlignSharedLibs);
+ }
}
bail: