应用加固后,再次签名的时候(使用了Qihoo360 Apk Signer
),签名后的文件名类似这样AS18_signed_Aligned.apk
,没有携带版本号,如果那么多渠道一个一个手动去改,麻烦不说还容易错。
所以就自己写个批量重命名的工具类。
重命名前文件名为AS18_signed_Aligned.apk
,
重命名后文件名为AS18_signed_
输入的内容.apk
import java.io.File;
import java.util.Scanner;
public class Test {
private static String sVersionName;
private static String sReplaceName = "Aligned";
public static void main(String[] ar) {
// File file = new File("");
// System.out.println(file.getAbsoluteFile());
sVersionName = getVersionCode();
File directory = getCurrentDirectory();
getFileName(directory);
}
private static File getCurrentDirectory() {
File file = new File("");
System.out.println(file.getAbsoluteFile());
return file.getAbsoluteFile();
}
private static String getVersionCode() {
System.out.println("input your version code ,like [v1.1.8]");
Scanner scanner = new Scanner(System.in);
String code = scanner.next();
System.out.println("input version code success , code is = " + sVersionName);
return code;
}
private static void getFileName(File file) {
if (file == null) {
System.out.println("file == null");
return;
}
if (sVersionName == null) {
System.out.println("sVersionName == null");
return;
}
if (file.isDirectory()) {
File[] files = file.listFiles();
if (files == null) {
System.out.println("files == null");
return;
}
System.out.println("files.length = " + files.length);
for (int i = 0; i < files.length; i++) {
getFileName(files[i]);
}
} else if (file.isFile()) {
String name = file.getName();
if (name.contains(sReplaceName)) {
String path = file.getAbsolutePath().replace(sReplaceName, sVersionName);
boolean aligned = file.renameTo(new File(path));
if (aligned) {
System.out.println("rename success, path : " + path);
} else {
System.out.println("warning !! rename failure, path : " + path);
}
}
} else {
System.out.println("file is not Directory or File");
}
}
}