简体   繁体   English

Gradle Android构建:如何为使用的Android命令行构建工具指定选项。

[英]Gradle Android build: how to specify options for the Android command line build tools used..?

When I use Gradle to build my Android app, it executes a whole chain of Android command line build tools like 'dx' to build my apk. 当我使用Gradle构建我的Android应用时,它会执行整个Android命令行构建工具链,例如“ dx”来构建我的apk。

Those command line tools all have 'options'. 这些命令行工具都具有“选项”。 I would like to specify some of these options within my Gradle build. 我想在我的Gradle版本中指定其中一些选项。 How is this possible? 这怎么可能?

Check out this answer , which shows that you can use dexTask.additionalParameters to pass additional arguments to the dx tool. 看看这个答案 ,它表明您可以使用dexTask.additionalParameters将其他参数传递给dx工具。 An easy way to get access to the dexTask is from the variants list: 从变体列表中可以轻松访问dexTask

android.applicationVariants.all { variant ->
    Dex dexTask = variant.dex
    if (dexTask.additionalParameters == null) dex.additionalParameters = []
    // This is just an example:
    dexTask.additionalParameters += '--help'
    // you could use others, such as '--multi-dex', or anything else that appears in the '--help' output.
}

From the source of AndroidBuilder.java , you can see which commandline arguments are already being added to the dx tool before appending your additionalParameters . AndroidBuilder.java ,你可以看到已经被添加到该命令行参数dx工具追加你之前additionalParameters

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM