2014-07-24 47 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