完善自动打包工具
广告源配置文件新增过滤包名 新增aapt.exe,安卓自带的有bug,用不了aapt r命令 穿山甲打包程序还有bug
This commit is contained in:
parent
c43093b119
commit
19e7e49fe7
@ -139,6 +139,7 @@
|
|||||||
"TMProvider": "TProvider"
|
"TMProvider": "TProvider"
|
||||||
},
|
},
|
||||||
"isAllPackage": true,
|
"isAllPackage": true,
|
||||||
|
"regexPackage":".qy",
|
||||||
"isReName": true,
|
"isReName": true,
|
||||||
"isJarLib": true,
|
"isJarLib": true,
|
||||||
"packagerlimit": 3,
|
"packagerlimit": 3,
|
||||||
|
@ -40,7 +40,7 @@ public class AutoPackageSDK {
|
|||||||
|
|
||||||
JSONArray array = new JSONArray();
|
JSONArray array = new JSONArray();
|
||||||
|
|
||||||
/* JSONObject gdt = new JSONObject();
|
JSONObject gdt = new JSONObject();
|
||||||
gdt.put("file", gdtsdk.getAbsolutePath());
|
gdt.put("file", gdtsdk.getAbsolutePath());
|
||||||
gdt.put("version", version);
|
gdt.put("version", version);
|
||||||
gdt.put("type", "1");
|
gdt.put("type", "1");
|
||||||
@ -54,7 +54,7 @@ public class AutoPackageSDK {
|
|||||||
unplay.put("type", "5");
|
unplay.put("type", "5");
|
||||||
unplay.put("index", 1);
|
unplay.put("index", 1);
|
||||||
unplay.put("packageName", packageName + ".up");
|
unplay.put("packageName", packageName + ".up");
|
||||||
array.put(unplay);*/
|
array.put(unplay);
|
||||||
|
|
||||||
JSONObject qy = new JSONObject();
|
JSONObject qy = new JSONObject();
|
||||||
qy.put("file", qysdk.getAbsolutePath());
|
qy.put("file", qysdk.getAbsolutePath());
|
||||||
@ -183,18 +183,19 @@ public class AutoPackageSDK {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void zip(File file,OutputStream stream) throws IOException {
|
private void zip(File file,OutputStream stream) throws Exception {
|
||||||
File sdk = new File("packageSDK" + File.separator + "sdk.aar");
|
File sdk = new File("packageSDK" + File.separator + "sdk.aar");
|
||||||
File files=new File("packageSDK");
|
File files=new File("packageSDK");
|
||||||
|
String aapt=new File("aapt.exe").exists()?new File("aapt.exe").getAbsolutePath():"aapt";
|
||||||
for (File listFile : file.listFiles()) {
|
for (File listFile : file.listFiles()) {
|
||||||
if(listFile.isDirectory()){
|
if(listFile.isDirectory()){
|
||||||
zip(listFile,stream);
|
zip(listFile,stream);
|
||||||
}else if(!listFile.getName().equals("sdk.aar")){
|
}else if(!listFile.getName().equals("sdk.aar")){
|
||||||
String path=listFile.getAbsolutePath().replace(files.getAbsolutePath(),"");
|
String path=listFile.getAbsolutePath().replace(files.getAbsolutePath(),"");
|
||||||
String exec="aapt r "+sdk.getAbsolutePath()+" "+path.substring(1)+"\n";
|
String exec=aapt+" r "+sdk.getAbsolutePath()+" "+path.substring(1)+"\n";
|
||||||
stream.write(exec.getBytes());
|
stream.write(exec.getBytes());
|
||||||
stream.flush();
|
stream.flush();
|
||||||
exec="aapt a "+sdk.getAbsolutePath()+" "+path.substring(1)+"\n";
|
exec =aapt+ " a " + sdk.getAbsolutePath() + " " + path.substring(1) + "\n";
|
||||||
stream.write(exec.getBytes());
|
stream.write(exec.getBytes());
|
||||||
stream.flush();
|
stream.flush();
|
||||||
}
|
}
|
||||||
@ -206,7 +207,8 @@ public class AutoPackageSDK {
|
|||||||
Tools.copyFile(new File("input" + File.separator + "Documents" + File.separator + "sdk.aar").getAbsolutePath(),
|
Tools.copyFile(new File("input" + File.separator + "Documents" + File.separator + "sdk.aar").getAbsolutePath(),
|
||||||
new File("packageSDK").getAbsolutePath(), true);
|
new File("packageSDK").getAbsolutePath(), true);
|
||||||
String cd = "cd " + new File("packageSDK").getAbsolutePath() + "\n";
|
String cd = "cd " + new File("packageSDK").getAbsolutePath() + "\n";
|
||||||
OutputStream stream = Runtime.getRuntime().exec(new String[]{"cmd"}).getOutputStream();
|
Process process=Runtime.getRuntime().exec(new String[]{"cmd"});
|
||||||
|
OutputStream stream =process.getOutputStream();
|
||||||
stream.write(cd.getBytes());
|
stream.write(cd.getBytes());
|
||||||
stream.flush();
|
stream.flush();
|
||||||
zip(new File("packageSDK"),stream);
|
zip(new File("packageSDK"),stream);
|
||||||
|
@ -612,7 +612,7 @@ public class AutoRandomAdSDK {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//穿山甲视频会闪退
|
||||||
private void movesdk(File path, String toPath) {
|
private void movesdk(File path, String toPath) {
|
||||||
for (File file : path.listFiles()) {
|
for (File file : path.listFiles()) {
|
||||||
if (file.getName().equals("BuildConfig.smali")) {
|
if (file.getName().equals("BuildConfig.smali")) {
|
||||||
@ -622,9 +622,13 @@ public class AutoRandomAdSDK {
|
|||||||
if (packageName != null && file.getAbsolutePath().contains(packageName.replace(".", File.separator))) {
|
if (packageName != null && file.getAbsolutePath().contains(packageName.replace(".", File.separator))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
String sdkPackageName=config.isNull("regexPackage")?null:config.getString("regexPackage");
|
||||||
|
if(sdkPackageName!=null){
|
||||||
|
toPath=toPath.replace(sdkPackageName.replace(".",File.separator),"");
|
||||||
|
}
|
||||||
|
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
String tmp = toPath + File.separator + file.getName();
|
String tmp = toPath + File.separator + file.getName();
|
||||||
////System.out.println("创建文件夹:"+tmp);
|
|
||||||
new File(rootPath + File.separator + tmp).mkdirs();
|
new File(rootPath + File.separator + tmp).mkdirs();
|
||||||
movesdk(file, tmp);
|
movesdk(file, tmp);
|
||||||
} else {
|
} else {
|
||||||
@ -640,7 +644,7 @@ public class AutoRandomAdSDK {
|
|||||||
boolean data = file.renameTo(new File(rootPath + toPath, file.getName()));
|
boolean data = file.renameTo(new File(rootPath + toPath, file.getName()));
|
||||||
//System.out.println("移动文件:" + file.getAbsolutePath().replace(rootPath, "") + " 到 " + (rootPath + toPath) + " > " + fileName + " " + nowAdClass.get(fileName) + " >! " + data);
|
//System.out.println("移动文件:" + file.getAbsolutePath().replace(rootPath, "") + " 到 " + (rootPath + toPath) + " > " + fileName + " " + nowAdClass.get(fileName) + " >! " + data);
|
||||||
if (nowAdClass.containsKey(fileName)) {
|
if (nowAdClass.containsKey(fileName)) {
|
||||||
// System.out.println("移动文件:"+file.getAbsolutePath().replace(rootPath, "")+" 到 "+(rootPath + File.separator + toPath)+" > "+fileName+" "+nowAdClass.get(fileName));
|
// System.err.println("移动文件:"+file.getAbsolutePath().replace(rootPath, "")+" 到 "+toPath+" > "+fileName+" "+nowAdClass.get(fileName));
|
||||||
// //System.out.println(file.getAbsolutePath().replace(rootPath,"")+" "+toPath);
|
// //System.out.println(file.getAbsolutePath().replace(rootPath,"")+" "+toPath);
|
||||||
nowAdClass.put(fileName, new File(rootPath + File.separator + toPath));
|
nowAdClass.put(fileName, new File(rootPath + File.separator + toPath));
|
||||||
}
|
}
|
||||||
|
@ -34,9 +34,7 @@ public class JarToAJar {
|
|||||||
File outFile=new File(inName);
|
File outFile=new File(inName);
|
||||||
if(outFile.exists())
|
if(outFile.exists())
|
||||||
outFile.delete();
|
outFile.delete();
|
||||||
OutputStream outputStream = new FileOutputStream(
|
Tools.toZip(json.getString(json.getString("switch")), new File(inName), true,true);
|
||||||
new File(inName));
|
|
||||||
Tools.toZip(json.getString(json.getString("switch")), outputStream, true,true);
|
|
||||||
Tools.toAJar(dx,inName, outName);
|
Tools.toAJar(dx,inName, outName);
|
||||||
System.out.println(outName);
|
System.out.println(outName);
|
||||||
if(AppMain.isOpenWindows)
|
if(AppMain.isOpenWindows)
|
||||||
|
@ -3,6 +3,7 @@ package com.qy.utils;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.jar.JarOutputStream;
|
||||||
import java.util.zip.CRC32;
|
import java.util.zip.CRC32;
|
||||||
import java.util.zip.CheckedInputStream;
|
import java.util.zip.CheckedInputStream;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
@ -204,16 +205,14 @@ public class Tools {
|
|||||||
return json;
|
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();
|
long start = System.currentTimeMillis();
|
||||||
ZipOutputStream zos = null;
|
ZipOutputStream zos = null;
|
||||||
try {
|
try {
|
||||||
zos = new ZipOutputStream(out);
|
zos = new ZipOutputStream(new FileOutputStream(file));
|
||||||
zos.setMethod(ZipOutputStream.STORED);
|
|
||||||
zos.setLevel(0);
|
|
||||||
File sourceFile = new File(srcDir);
|
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();
|
long end = System.currentTimeMillis();
|
||||||
System.out.println("压缩完成,耗时:" + (end - start) + " ms");
|
System.out.println("压缩完成,耗时:" + (end - start) + " ms");
|
||||||
} catch (Exception e) {
|
} 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 {
|
throws Exception {
|
||||||
byte[] buf = new byte[ 2 * 1024];
|
byte[] buf = new byte[ 2 * 1024];
|
||||||
|
|
||||||
if (sourceFile.isFile()) {
|
if (sourceFile.isFile()) {
|
||||||
|
if(sourceFile.getName().equals(zipName)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 向zip输出流中添加一个zip实体,构造器中name为zip实体的文件的名字
|
// 向zip输出流中添加一个zip实体,构造器中name为zip实体的文件的名字
|
||||||
ZipEntry entry=new ZipEntry(name);
|
ZipEntry entry=new ZipEntry(name);
|
||||||
entry.setMethod(STORED);
|
/*entry.setMethod(STORED);
|
||||||
entry.setSize(sourceFile.length());
|
entry.setSize(sourceFile.length());
|
||||||
long crc=0;
|
long crc=0;
|
||||||
crc=calFileCRC32(sourceFile);
|
crc=calFileCRC32(sourceFile);
|
||||||
entry.setCrc(crc);
|
entry.setCrc(crc);*/
|
||||||
zos.putNextEntry(entry);
|
zos.putNextEntry(entry);
|
||||||
// copy文件到zip输出流中
|
// copy文件到zip输出流中
|
||||||
int len;
|
int len;
|
||||||
@ -257,7 +260,6 @@ public class Tools {
|
|||||||
if (KeepDirStructure) {
|
if (KeepDirStructure) {
|
||||||
// 空文件夹的处理
|
// 空文件夹的处理
|
||||||
ZipEntry entry=new ZipEntry(name + File.separator);
|
ZipEntry entry=new ZipEntry(name + File.separator);
|
||||||
entry.setMethod(STORED);
|
|
||||||
zos.putNextEntry(entry);
|
zos.putNextEntry(entry);
|
||||||
// 没有文件,不需要文件的copy
|
// 没有文件,不需要文件的copy
|
||||||
zos.closeEntry();
|
zos.closeEntry();
|
||||||
@ -270,16 +272,16 @@ public class Tools {
|
|||||||
// 注意:file.getName()前面需要带上父文件夹的名字加一斜杠,
|
// 注意:file.getName()前面需要带上父文件夹的名字加一斜杠,
|
||||||
// 不然最后压缩包中就不能保留原来的文件结构,即:所有文件都跑到压缩包根目录下了
|
// 不然最后压缩包中就不能保留原来的文件结构,即:所有文件都跑到压缩包根目录下了
|
||||||
if(zipRootName) {
|
if(zipRootName) {
|
||||||
compress(file, zos, name + File.separator + file.getName(), KeepDirStructure,zipRootName);
|
compress(file, zos, zipName,name + File.separator + file.getName(), KeepDirStructure,zipRootName);
|
||||||
}else{
|
}else{
|
||||||
if(name.startsWith("\\")){
|
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 {
|
}else {
|
||||||
compress(file, zos, File.separator + file.getName(), KeepDirStructure, zipRootName);
|
compress(file, zos,zipName, File.separator + file.getName(), KeepDirStructure, zipRootName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
compress(file, zos, file.getName(), KeepDirStructure,zipRootName);
|
compress(file, zos, zipName,file.getName(), KeepDirStructure,zipRootName);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user