完善自动打包工具

广告源配置文件新增过滤包名
新增aapt.exe,安卓自带的有bug,用不了aapt r命令
穿山甲打包程序还有bug
This commit is contained in:
2020-03-17 09:03:45 +08:00
parent c43093b119
commit 19e7e49fe7
6 changed files with 32 additions and 25 deletions

View File

@@ -3,6 +3,7 @@ package com.qy.utils;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Random;
import java.util.jar.JarOutputStream;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import java.util.zip.ZipEntry;
@@ -204,16 +205,14 @@ public class Tools {
return json;
}
public static void toZip(String srcDir, OutputStream out, boolean KeepDirStructure,boolean zipRootName) throws RuntimeException {
public static void toZip(String srcDir, File file, boolean KeepDirStructure,boolean zipRootName) throws RuntimeException {
long start = System.currentTimeMillis();
ZipOutputStream zos = null;
try {
zos = new ZipOutputStream(out);
zos.setMethod(ZipOutputStream.STORED);
zos.setLevel(0);
zos = new ZipOutputStream(new FileOutputStream(file));
File sourceFile = new File(srcDir);
compress(sourceFile, zos, sourceFile.getName(), KeepDirStructure,zipRootName);
compress(sourceFile, zos,file.getName(), sourceFile.getName(), KeepDirStructure,zipRootName);
long end = System.currentTimeMillis();
System.out.println("压缩完成,耗时:" + (end - start) + " ms");
} catch (Exception e) {
@@ -229,17 +228,21 @@ public class Tools {
}
}
private static void compress(File sourceFile, ZipOutputStream zos, String name, boolean KeepDirStructure,boolean zipRootName)
private static void compress(File sourceFile, ZipOutputStream zos,String zipName, String name, boolean KeepDirStructure,boolean zipRootName)
throws Exception {
byte[] buf = new byte[ 2 * 1024];
if (sourceFile.isFile()) {
if(sourceFile.getName().equals(zipName)){
return;
}
// 向zip输出流中添加一个zip实体构造器中name为zip实体的文件的名字
ZipEntry entry=new ZipEntry(name);
entry.setMethod(STORED);
/*entry.setMethod(STORED);
entry.setSize(sourceFile.length());
long crc=0;
crc=calFileCRC32(sourceFile);
entry.setCrc(crc);
entry.setCrc(crc);*/
zos.putNextEntry(entry);
// copy文件到zip输出流中
int len;
@@ -257,7 +260,6 @@ public class Tools {
if (KeepDirStructure) {
// 空文件夹的处理
ZipEntry entry=new ZipEntry(name + File.separator);
entry.setMethod(STORED);
zos.putNextEntry(entry);
// 没有文件不需要文件的copy
zos.closeEntry();
@@ -270,16 +272,16 @@ public class Tools {
// 注意file.getName()前面需要带上父文件夹的名字加一斜杠,
// 不然最后压缩包中就不能保留原来的文件结构,即:所有文件都跑到压缩包根目录下了
if(zipRootName) {
compress(file, zos, name + File.separator + file.getName(), KeepDirStructure,zipRootName);
compress(file, zos, zipName,name + File.separator + file.getName(), KeepDirStructure,zipRootName);
}else{
if(name.startsWith("\\")){
compress(file, zos, name + File.separator + file.getName(), KeepDirStructure,zipRootName);
compress(file, zos, zipName,name + File.separator + file.getName(), KeepDirStructure,zipRootName);
}else {
compress(file, zos, File.separator + file.getName(), KeepDirStructure, zipRootName);
compress(file, zos,zipName, File.separator + file.getName(), KeepDirStructure, zipRootName);
}
}
} else {
compress(file, zos, file.getName(), KeepDirStructure,zipRootName);
compress(file, zos, zipName,file.getName(), KeepDirStructure,zipRootName);
}
}