improve NPatch zip handling

將 android:largeHeap="true" 添加至管理員 manifest 中,防止系統限制 RAM。啟用 ZFileOptions.setNoTimestamps,並將來源 APK 嵌入為唯讀壓縮檔。
This commit is contained in:
NkBe 2026-02-10 19:26:10 +08:00
parent 97a23caa9e
commit c1480fa121
No known key found for this signature in database
GPG Key ID: 9FACEE0DB6DF678E
2 changed files with 9 additions and 6 deletions

View File

@ -23,6 +23,7 @@
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:supportsRtl="true" android:supportsRtl="true"
android:largeHeap="true"
android:theme="@style/Theme.Material3.DayNight.NoActionBar"> android:theme="@style/Theme.Material3.DayNight.NoActionBar">
<!-- 专门为小米手机桌面卸载添加了提示,提升用户体验 --> <!-- 专门为小米手机桌面卸载添加了提示,提升用户体验 -->

View File

@ -118,11 +118,13 @@ public class NPatch {
"x86_64" "x86_64"
)); ));
private static final ZFileOptions Z_FILE_OPTIONS = new ZFileOptions().setAlignmentRule(AlignmentRules.compose( private static final ZFileOptions Z_FILE_OPTIONS = new ZFileOptions()
AlignmentRules.constantForSuffix(".so", 4096), .setNoTimestamps(true)
AlignmentRules.constantForSuffix(ORIGINAL_APK_ASSET_PATH, 4096), .setAlignmentRule(AlignmentRules.compose(
AlignmentRules.constantForSuffix(".arsc", 4) AlignmentRules.constantForSuffix(".so", 4096),
)); AlignmentRules.constantForSuffix(ORIGINAL_APK_ASSET_PATH, 4096),
AlignmentRules.constantForSuffix(".arsc", 4)
));
private final JCommander jCommander; private final JCommander jCommander;
@ -196,7 +198,7 @@ public class NPatch {
logger.i("Parsing original apk..."); logger.i("Parsing original apk...");
try (var dstZFile = ZFile.openReadWrite(outputFile, Z_FILE_OPTIONS); try (var dstZFile = ZFile.openReadWrite(outputFile, Z_FILE_OPTIONS);
var srcZFile = dstZFile.addNestedZip((ignore) -> ORIGINAL_APK_ASSET_PATH, srcApkFile, false)) { var srcZFile = ZFile.openReadOnly(srcApkFile)) {
// sign apk // sign apk
try { try {