【问题标题】:Build dex file using gradle使用 gradle 构建 dex 文件
【发布时间】:2014-09-16 12:20:15
【问题描述】:

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

这些项目是主要的应用模块并在运行时加载。

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

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

【问题讨论】:

    标签: android build gradle dex


    【解决方案1】:

    您需要手动调用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

    【讨论】:

      猜你喜欢
      • 2014-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-31
      • 2015-02-25
      相关资源
      最近更新 更多