package zip;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
public class ziptest {
private static File apktool = null;
private static File signapk = null;
private static File testkey_pk8 = null;
private static File testkey_x509_pem = null;
private static File dirFile;// 根目录
public static void main(String args[]) throws IOException{
Process process = null;
apktool = new File(dirFile.getAbsolutePath(), "apktool.bat");
dirFile = new File(System.getProperty("user.dir"));
signapk = new File(dirFile.getAbsolutePath(), "signapk.jar");
testkey_pk8 = new File(dirFile.getAbsolutePath(), "testkey.pk8");
testkey_x509_pem = new File(dirFile.getAbsolutePath(), "testkey.x509.pem");
try {
//1----解压
//apktool路径
//String path = "E:\\apktool\\apktool.bat";
//保存路径
String appPath = "E:\\newapk\\";
//process = Runtime.getRuntime().exec("cmd.exe /c"+path+" apktool d "+appPath+"lvping.apk -o"+appPath+"apk");
process = Runtime.getRuntime().exec("cmd.exe /c"+apktool.getPath() + " d –f "+appPath+"lvping.apk -o"+appPath+"apk");
if(process.waitFor()!=0)System.out.println("解压失败!");
//2----添加json文件
String filePath ="E:\\newapk\\apk";
File f = new File(filePath);
File[] fis = f.listFiles();
for(File ff:fis) {
String paths = ff.getAbsolutePath();
if(paths.contains("assets")) {
String fPath = "E:\\newapk\\apk\\assets";
CreateJson(fPath);
}else {
String fPath =filePath+"\\assets";
File fs = new File(fPath);
CreateJson(fPath);
fs.mkdirs();
}
}
//3----打包
// process = Runtime.getRuntime().exec("cmd.exe /c"+path+" b "+appPath+"apk -o"+appPath+"app.apk");
process = Runtime.getRuntime().exec("cmd.exe /c"+apktool.getPath() +" b "+appPath+"apk -o"+appPath+"app.apk");
if(process.waitFor()!=0)System.out.println("打包失败!");
//4----签名 (文件名称中不能包含空格)
//String cmd = "cmd.exe /c E:\
Android--解包、添加文件、打包、签名
最新推荐文章于 2022-11-26 09:29:45 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)