private void UnPack_Logic() { OutPut("【I】"); if (Apktool.isApkFile(file.Text)) // 解包 { OutPut("【I】apk解包开始..."); String result = Apktool.unPackage(file.Text, OutPut, false, false); // 使用apktool进行apk的解包 if (result.Contains("【E】")) { return; } OutPut("【I】apk解包结束!\r\n"); } else if (Apktool.isApkDir(file.Text)) // 打包 { OutPut("【I】apk打包开始..."); String result = Apktool.package(file.Text, OutPut); // 使用apktool进行打包 if (result.Contains("【E】")) { return; } OutPut("【I】apk未签名文件已生成!\r\n"); // 若有签名文件,则进行签名 if (!comboBox_sign.Text.Equals("")) { OutPut("【I】apk签名中..."); String apkName = file.Text + "..apk"; String pem = SinPath() + "\\" + comboBox_sign.Text + ".x509.pem"; String pk8 = SinPath() + "\\" + comboBox_sign.Text + ".pk8"; String psw = "letang123"; result = Apktool.Sign(apkName, pem, pk8, psw, OutPut); if (result.Contains("【E】")) { return; } OutPut("【I】apk签名、对齐 完成!\r\n"); // 删除打包生成的未签名文件 if (System.IO.File.Exists(apkName)) { System.IO.File.Delete(apkName); } } OutPut("【I】apk打包结束!\r\n"); } else { Cmd.Run(file.Text, OutPut); // 执行cmd命令 } }
/// <summary> /// 执行apk打包逻辑 /// </summary> public static String apkPackage(String apkUnPackageDir, String signFileName, Cmd.Callback call) { // 重新打包apk,并签名 if (call != null) { call("【I】apk打包开始..."); } String result = Apktool.package(apkUnPackageDir, call); // 使用apktool进行打包 if (result.Contains("【E】")) { return(result); } if (call != null) { call("【I】apk未签名文件已生成!\r\n"); } // 若有签名文件,则进行签名 if (!signFileName.Equals("")) { if (call != null) { call("【I】apk签名中..."); } String apkName = apkUnPackageDir + "..apk"; if (signFileName.EndsWith(".keystore")) { String keysotreName = Form1.SinPath() + "\\" + signFileName; String[] I = getKestoreInfo(signFileName); // 获取对应的签名信息 String alias = I[0]; String password = I[1]; result = Apktool.SignKeyStore(apkName, keysotreName, alias, password, call); } else { String pem = Form1.SinPath() + "\\" + signFileName + ".x509.pem"; String pk8 = Form1.SinPath() + "\\" + signFileName + ".pk8"; String psw = "letang123"; result = Apktool.Sign(apkName, pem, pk8, psw, call); } if (result.Contains("【E】")) { return(result); } if (call != null) { call("【I】apk签名、对齐 完成!\r\n"); } // 删除打包生成的未签名文件 if (File.Exists(apkName)) { File.Delete(apkName); } } if (call != null) { call("【I】apk打包结束!\r\n"); } return(""); }