capacitor-dex-editor 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1738,54 +1738,54 @@ public class DexManager {
1738
1738
 
1739
1739
  zipFile.close();
1740
1740
 
1741
- // 2. 直接替换 APK 中的 DEX(MT 管理器的方式)
1742
- // 使用 ZipOutputStream 重新写入 APK,只替换 DEX 部分
1741
+ // 2. MT 风格:使用 ZipInputStream 流式处理替换 DEX
1743
1742
  java.io.File apkFile = new java.io.File(apkPath);
1744
1743
  java.io.File tempApkFile = new java.io.File(apkPath + ".tmp");
1744
+ byte[] newDexBytes = readFileBytes(mergedDexFile);
1745
1745
 
1746
- Log.d(TAG, "Replacing DEX in APK...");
1746
+ Log.d(TAG, "Replacing DEX in APK (MT style stream)...");
1747
1747
 
1748
- java.util.zip.ZipFile originalZip = new java.util.zip.ZipFile(apkFile);
1748
+ java.util.zip.ZipInputStream zis = new java.util.zip.ZipInputStream(
1749
+ new java.io.BufferedInputStream(new java.io.FileInputStream(apkFile)));
1749
1750
  java.util.zip.ZipOutputStream zos = new java.util.zip.ZipOutputStream(
1750
1751
  new java.io.BufferedOutputStream(new java.io.FileOutputStream(tempApkFile)));
1751
1752
 
1752
- // 设置不压缩,加快速度
1753
- zos.setMethod(java.util.zip.ZipOutputStream.STORED);
1754
-
1755
- java.util.Enumeration<? extends java.util.zip.ZipEntry> entries = originalZip.entries();
1756
- while (entries.hasMoreElements()) {
1757
- java.util.zip.ZipEntry entry = entries.nextElement();
1758
-
1753
+ java.util.zip.ZipEntry entry;
1754
+ while ((entry = zis.getNextEntry()) != null) {
1759
1755
  if (entry.getName().equals(dexPath)) {
1760
- // 替换 DEX 文件
1761
- byte[] dexBytes = readFileBytes(mergedDexFile);
1756
+ // 替换 DEX:写入新数据
1762
1757
  java.util.zip.ZipEntry newEntry = new java.util.zip.ZipEntry(dexPath);
1763
- newEntry.setMethod(java.util.zip.ZipEntry.STORED);
1764
- newEntry.setSize(dexBytes.length);
1765
- newEntry.setCompressedSize(dexBytes.length);
1766
- newEntry.setCrc(calculateCrc32(dexBytes));
1758
+ newEntry.setMethod(java.util.zip.ZipEntry.DEFLATED);
1767
1759
  zos.putNextEntry(newEntry);
1768
- zos.write(dexBytes);
1760
+ zos.write(newDexBytes);
1769
1761
  zos.closeEntry();
1762
+ // 跳过原 DEX 数据
1763
+ zis.closeEntry();
1770
1764
  } else {
1771
- // 复制原条目(保持原压缩方式)
1772
- java.util.zip.ZipEntry newEntry = new java.util.zip.ZipEntry(entry);
1765
+ // 直接复制其他条目(流式,不解压到磁盘)
1766
+ java.util.zip.ZipEntry newEntry = new java.util.zip.ZipEntry(entry.getName());
1767
+ newEntry.setTime(entry.getTime());
1768
+ if (entry.getMethod() == java.util.zip.ZipEntry.STORED) {
1769
+ newEntry.setMethod(java.util.zip.ZipEntry.STORED);
1770
+ newEntry.setSize(entry.getSize());
1771
+ newEntry.setCrc(entry.getCrc());
1772
+ } else {
1773
+ newEntry.setMethod(java.util.zip.ZipEntry.DEFLATED);
1774
+ }
1773
1775
  zos.putNextEntry(newEntry);
1774
1776
  if (!entry.isDirectory()) {
1775
- java.io.InputStream is = originalZip.getInputStream(entry);
1776
1777
  byte[] buf = new byte[8192];
1777
1778
  int n;
1778
- while ((n = is.read(buf)) != -1) {
1779
+ while ((n = zis.read(buf)) != -1) {
1779
1780
  zos.write(buf, 0, n);
1780
1781
  }
1781
- is.close();
1782
1782
  }
1783
1783
  zos.closeEntry();
1784
1784
  }
1785
1785
  }
1786
1786
 
1787
+ zis.close();
1787
1788
  zos.close();
1788
- originalZip.close();
1789
1789
 
1790
1790
  // 用临时文件替换原文件
1791
1791
  if (!apkFile.delete()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-dex-editor",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Capacitor-plugin-for-editing-DEX-files-in-APK",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",