我尝试使用gradle自动化我的应用构建过程。构建步骤之一是从android库项目生成dex文件。
这些项目是主要的应用程序模块,并在运行时加载。
在当前的构建过程中,我构建了库的jar并使用脚本将其转换为dex。它由eclipse构建命令完成。
有没有办法以及如何使用gradle进行操作?
答案 0 :(得分:0)
您需要手动调用dx
,例如
task finalize() {
doFirst {
println('Encrypting!')
println("${projectDir}")
exec {
workingDir "${projectDir}/build/intermediates/classes/debug"
commandLine "/home/gelldur/Android/Sdk/build-tools/26.0.0/dx" \
, "--dex" \
, "--output=drozd/dawid/dexode/com/secureme/SecuredData.dex" \
, "drozd/dawid/dexode/com/secureme/SecuredData.class"
}
//We don't want in our APK this .class
project.delete "build/intermediates/classes/debug/drozd/dawid/dexode/com/secureme/SecuredData.class"
// Encrypt our .dex file
encrypt.execute()
copy {
from "build/intermediates/classes/debug/drozd/dawid/dexode/com/secureme/SecuredData.dex"
into "src/main/assets/"
}
}
}
tasks.withType(JavaCompile) { compileTask -> compileTask.finalizedBy finalize }
完整示例here