Код: Выделить всё
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)
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... ild-gradle