Skip to content

Commit

Permalink
修复 Windows 环境 signApk.renameTo() 失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
mcxinyu committed Mar 7, 2023
1 parent cae7d5a commit acb6e51
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions file-plugin/src/main/java/com/mainli/apk/ApkSign.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public static File sign(File inputApk, SigningConfig signingConfig, int minSdkVe
String keystoreAlias = signingConfig.getKeyAlias();
String keystoreAliasPassworld = signingConfig.getKeyPassword();
File outputApk = new File(inputApk.getParentFile(), "_single.apk");
if (outputApk.exists()) {
boolean delete = outputApk.delete();
}
String defaultType = KeyStore.getDefaultType();//jks
try {
KeyStore ks = KeyStore.getInstance(defaultType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ open class ApkSoLibStreamlineTask @Inject constructor(
if (newApk?.exists() == true) {
val signApk = ApkSign.sign(newApk, variant)
newApk.delete()
apkFile.renameTo(File(apkFile.parentFile, "backup-" + apkFile.name))
signApk.renameTo(apkFile)
val newSize = apkFile.length()
val oldSizeM = oldSize / 1024f / 1024f
val newSizeM = newSize / 1024f / 1024f
val changeSizeM = (oldSize - newSize) / 1024f / 1024f
log("处理前Apk Size:${oldSizeM}M, 处理后Apk Size:${newSizeM}M, 优化 Size${changeSizeM}M")
log("处理前Apk Size: ${oldSizeM}M, 处理后Apk Size: ${newSizeM}M, 优化 Size: ${changeSizeM}M")
}
}
}
Expand All @@ -69,13 +70,19 @@ open class ApkSoLibStreamlineTask @Inject constructor(
return null
}
val outPutApk = File(apk.parentFile, "_streamlineApkBySoFile.apk")
if (outPutApk.exists()) {
outPutApk.delete()
}
var inputZip: ZipFile? = null
var zipOutputStream: ZipOutputStream? = null
try {
inputZip = ZipFile(apk)
val inputEntries = inputZip.entries()
zipOutputStream = ZipOutputStream(FileOutputStream(outPutApk))
val streamlineFile = File(apk.canonicalFile.parentFile, "streamline")
if (streamlineFile.exists()) {
streamlineFile.delete()
}
while (inputEntries.hasMoreElements()) {
val inputZipEntry = inputEntries.nextElement()
val name = inputZipEntry.name
Expand Down

0 comments on commit acb6e51

Please sign in to comment.