diff --git a/aapt.exe b/aapt.exe new file mode 100644 index 0000000..e8a695e Binary files /dev/null and b/aapt.exe differ diff --git a/ad_config.cfg b/ad_config.cfg index 5506825..47f43a8 100644 --- a/ad_config.cfg +++ b/ad_config.cfg @@ -139,6 +139,7 @@ "TMProvider": "TProvider" }, "isAllPackage": true, + "regexPackage":".qy", "isReName": true, "isJarLib": true, "packagerlimit": 3, diff --git a/src/com/qy/utils/AutoPackageSDK.java b/src/com/qy/utils/AutoPackageSDK.java index d39dc02..c408a52 100644 --- a/src/com/qy/utils/AutoPackageSDK.java +++ b/src/com/qy/utils/AutoPackageSDK.java @@ -40,7 +40,7 @@ public class AutoPackageSDK { JSONArray array = new JSONArray(); - /* JSONObject gdt = new JSONObject(); + JSONObject gdt = new JSONObject(); gdt.put("file", gdtsdk.getAbsolutePath()); gdt.put("version", version); gdt.put("type", "1"); @@ -54,7 +54,7 @@ public class AutoPackageSDK { unplay.put("type", "5"); unplay.put("index", 1); unplay.put("packageName", packageName + ".up"); - array.put(unplay);*/ + array.put(unplay); JSONObject qy = new JSONObject(); qy.put("file", qysdk.getAbsolutePath()); @@ -183,18 +183,19 @@ public class AutoPackageSDK { 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 files=new File("packageSDK"); + String aapt=new File("aapt.exe").exists()?new File("aapt.exe").getAbsolutePath():"aapt"; for (File listFile : file.listFiles()) { if(listFile.isDirectory()){ zip(listFile,stream); }else if(!listFile.getName().equals("sdk.aar")){ 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.flush(); - exec="aapt a "+sdk.getAbsolutePath()+" "+path.substring(1)+"\n"; + exec =aapt+ " a " + sdk.getAbsolutePath() + " " + path.substring(1) + "\n"; stream.write(exec.getBytes()); stream.flush(); } @@ -206,7 +207,8 @@ public class AutoPackageSDK { Tools.copyFile(new File("input" + File.separator + "Documents" + File.separator + "sdk.aar").getAbsolutePath(), new File("packageSDK").getAbsolutePath(), true); 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.flush(); zip(new File("packageSDK"),stream); diff --git a/src/com/qy/utils/AutoRandomAdSDK.java b/src/com/qy/utils/AutoRandomAdSDK.java index 81e22a0..addee25 100644 --- a/src/com/qy/utils/AutoRandomAdSDK.java +++ b/src/com/qy/utils/AutoRandomAdSDK.java @@ -612,7 +612,7 @@ public class AutoRandomAdSDK { } } - + //穿山甲视频会闪退 private void movesdk(File path, String toPath) { for (File file : path.listFiles()) { if (file.getName().equals("BuildConfig.smali")) { @@ -622,9 +622,13 @@ public class AutoRandomAdSDK { if (packageName != null && file.getAbsolutePath().contains(packageName.replace(".", File.separator))) { continue; } + String sdkPackageName=config.isNull("regexPackage")?null:config.getString("regexPackage"); + if(sdkPackageName!=null){ + toPath=toPath.replace(sdkPackageName.replace(".",File.separator),""); + } + if (file.isDirectory()) { String tmp = toPath + File.separator + file.getName(); - ////System.out.println("创建文件夹:"+tmp); new File(rootPath + File.separator + tmp).mkdirs(); movesdk(file, tmp); } else { @@ -640,7 +644,7 @@ public class AutoRandomAdSDK { boolean data = file.renameTo(new File(rootPath + toPath, file.getName())); //System.out.println("移动文件:" + file.getAbsolutePath().replace(rootPath, "") + " 到 " + (rootPath + toPath) + " > " + fileName + " " + nowAdClass.get(fileName) + " >! " + data); 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); nowAdClass.put(fileName, new File(rootPath + File.separator + toPath)); } diff --git a/src/com/qy/utils/JarToAJar.java b/src/com/qy/utils/JarToAJar.java index 963bf21..378cc47 100755 --- a/src/com/qy/utils/JarToAJar.java +++ b/src/com/qy/utils/JarToAJar.java @@ -34,9 +34,7 @@ public class JarToAJar { File outFile=new File(inName); if(outFile.exists()) outFile.delete(); - OutputStream outputStream = new FileOutputStream( - new File(inName)); - Tools.toZip(json.getString(json.getString("switch")), outputStream, true,true); + Tools.toZip(json.getString(json.getString("switch")), new File(inName), true,true); Tools.toAJar(dx,inName, outName); System.out.println(outName); if(AppMain.isOpenWindows) diff --git a/src/com/qy/utils/Tools.java b/src/com/qy/utils/Tools.java index 32fe69b..2415a35 100755 --- a/src/com/qy/utils/Tools.java +++ b/src/com/qy/utils/Tools.java @@ -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); } }