Skip to content

Commit

Permalink
改进
Browse files Browse the repository at this point in the history
  • Loading branch information
maoabc committed Aug 8, 2022
1 parent 7fcca82 commit 867fbae
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,23 @@ public void run() throws IOException {
//add AndroidManifest.xml
addInputStreamToZip(zipOutput,
new ByteArrayInputStream(manifestBytes),
ANDROID_MANIFEST_XML);
new ZipEntry(ANDROID_MANIFEST_XML));

//add classesX.dex
for (File file : outDexFiles) {
addFileToZip(zipOutput, file, file.getName());
final ZipEntry zipEntry = new ZipEntry(file.getName());

addFileToZip(zipOutput, file, zipEntry);
}

//add native libs
for (Map.Entry<String, List<File>> entry : nativeLibs.entrySet()) {
final String abi = entry.getKey();
for (File file : entry.getValue()) {
addFileToZip(zipOutput, file, "lib/" + abi + "/" + file.getName());
final ZipEntry zipEntry = new ZipEntry("lib/" + abi + "/" + file.getName());
//todo 可能不需要压缩.so文件,同时保证.so文件4k对齐

addFileToZip(zipOutput, file, zipEntry);
}
}
}
Expand All @@ -163,17 +168,15 @@ public void run() throws IOException {
}
}

private void addFileToZip(ZipOutputStream zipOutput, File file, String entryName) throws IOException {
final ZipEntry zipEntry = new ZipEntry(entryName);
private void addFileToZip(ZipOutputStream zipOutput, File file, ZipEntry zipEntry) throws IOException {
zipOutput.putNextEntry(zipEntry);
try (FileInputStream input = new FileInputStream(file);) {
FileUtils.copyStream(input, zipOutput);
}
zipOutput.closeEntry();
}

private void addInputStreamToZip(ZipOutputStream zipOutput, InputStream inputStream, String entryName) throws IOException {
final ZipEntry zipEntry = new ZipEntry(entryName);
private void addInputStreamToZip(ZipOutputStream zipOutput, InputStream inputStream, ZipEntry zipEntry) throws IOException {
zipOutput.putNextEntry(zipEntry);
try {
FileUtils.copyStream(inputStream, zipOutput);
Expand Down Expand Up @@ -606,7 +609,6 @@ private static String classDotNameToType(String classDotName) {
}



public static class Builder {
private final ApkFolders apkFolders;
private InstructionRewriter instructionRewriter;
Expand Down

0 comments on commit 867fbae

Please sign in to comment.