使用gradle构建dex文件

问题描述 投票:0回答:1

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

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

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

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

android build gradle dex
1个回答
1
投票

您需要手动调用

dx
例如。

task finalize() {
    doFirst {
        println('Encrypting!')
        println("${projectDir}")

        exec {
            workingDir "${projectDir}/build/intermediates/classes/debug"
            commandLine "/home/MyUser/Android/Sdk/build-tools/26.0.0/dx"             \
            , "--dex"             \
            , "--output=my/example/com/secureme/SecuredData.dex"             \
            , "my/example/com/secureme/SecuredData.class"
        }
        //We don't want in our APK this .class
        project.delete "build/intermediates/classes/debug/my/example/com/secureme/SecuredData.class"

        // Encrypt our .dex file
        encrypt.execute()

        copy {
            from "build/intermediates/classes/debug/my/example/com/secureme/SecuredData.dex"
            into "src/main/assets/"
        }
    }
}

tasks.withType(JavaCompile) { compileTask -> compileTask.finalizedBy finalize }

完整示例此处

© www.soinside.com 2019 - 2024. All rights reserved.