2014-07-24 48 views
3

我正在尝试使用gradle自动化我的应用程序构建过程。构建步骤之一是从android库项目生成dex文件。使用gradle构建dex文件

这些项目是主要的应用程序模块和运行时加载。

在当前的构建过程中,我正在构建库的jar并使用脚本将其转换为dex。它由eclipse build命令完成。

有没有办法,如何用gradle做到这一点?

回答

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