applicationVariants.all { variant ->
variant.outputs.each { output ->
// Hook into the package task
tasks.named("package${variant.name.capitalize()}").configure { packageTask ->
packageTask.doLast {
println "Accessing source files before ZIP step"
def apkFile = output.outputFile
if (!apkFile.exists()) {
throw new GradleException("APK file does not exist: ${apkFile}")
}
def tmpDir = new File(buildDir, "tmp/renamedDexFiles")
if (tmpDir.exists()) {
tmpDir.deleteDir()
}
tmpDir.mkdirs()
// Extract APK
copy {
from zipTree(apkFile)
into tmpDir
}
def metaDir = new File(buildDir, "tmp/renamedDexFiles/META-INF")
if (metaDir.exists()) {
metaDir.deleteDir()
}
// Rename dex files in the temporary directory
tmpDir.listFiles().each { dexFile ->
if (dexFile.name.startsWith("classes") && dexFile.name.endsWith(".dex")) {
def containApplicationClass = containsApplicationClass(dexFile)
if (containApplicationClass) {
// dexFile.renameTo("${dexFile.parent}/CrashRestartApp.dex")
} else {
// def encryptingFilePath = "${dexFile.parent}/${dexFile.name}.enc"
//
// javaexec {
// classpath = files("${buildDir}/intermediates/javac/debug/classes")
// main = 'brightree.encryptor.DexEncryptor'
// println(dexFile)
// args dexFile, encryptingFilePath, secretKeyPath
// }
}
// delete dexFile
}
}
def newApkFile = new File(buildDir, "outputs/apk/debug/ant.zip.apk")
ant.zip(destfile: newApkFile, basedir: tmpDir)
}
}
}
}
Но после того, как заархивировать APK и подписать его, я не могу его установить. Он всегда возвращает сообщение «Приложение не установлено» без каких-либо других ошибок. Есть ли кто-нибудь, кто делал это раньше? Пожалуйста, порекомендуйте. Очень признателен!
Я выполняю задание по шифрованию файлов dex. Ниже приведен код, который я написал в build.gradle для шифрования и сжатия обратно в APK. [code]applicationVariants.all { variant -> variant.outputs.each { output -> // Hook into the package task tasks.named("package${variant.name.capitalize()}").configure { packageTask -> packageTask.doLast { println "Accessing source files before ZIP step"
def apkFile = output.outputFile if (!apkFile.exists()) { throw new GradleException("APK file does not exist: ${apkFile}") }
def tmpDir = new File(buildDir, "tmp/renamedDexFiles") if (tmpDir.exists()) { tmpDir.deleteDir() } tmpDir.mkdirs() // Extract APK copy { from zipTree(apkFile) into tmpDir } def metaDir = new File(buildDir, "tmp/renamedDexFiles/META-INF") if (metaDir.exists()) { metaDir.deleteDir() }
def newApkFile = new File(buildDir, "outputs/apk/debug/ant.zip.apk") ant.zip(destfile: newApkFile, basedir: tmpDir) } } } } [/code] Но после того, как заархивировать APK и подписать его, я не могу его установить. Он всегда возвращает сообщение «Приложение не установлено» без каких-либо других ошибок. Есть ли кто-нибудь, кто делал это раньше? Пожалуйста, порекомендуйте. Очень признателен!