應用加固後,再次簽名的時候(使用了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");
}
}
}
複製程式碼