【问题标题】:How can custom compilation parameters be synchronized through the Android studio project?如何通过Android studio项目同步自定义编译参数?
【发布时间】:2018-10-23 01:30:09
【问题描述】:

我的项目中有些参数需要在编译时传入。

所以我的build.gradle文件中有这样一个片段:

assemble {
    description 'Check the necessary parameters and terminate compilation if they do not exist.'
    if (!project.hasProperty('customArgs')) {
        throw new RuntimeException("Parameter customArgs is not defined")
    }
}

我编译的时候会使用命令gradle build -PcustomArgs=1234

在我将项目导入 Android Studio 之前一切都很好。

Gradle 项目同步总是失败。

也就是说,在项目同步的过程中,找不到可以设置参数的地方。

也就是说,如何在Android Studio中设置sync的参数?

【问题讨论】:

    标签: android-studio gradle gradle-plugin


    【解决方案1】:

    您应该将此自定义行为从配置阶段移至执行阶段。否则 Android Studio 会在配置你的项目时执行它。

    assemble {
        doLast {
            description 'Check the necessary parameters and terminate compilation if they do not exist.'
            if (!project.hasProperty('customArgs')) {
                throw new RuntimeException("Parameter customArgs is not defined")
            }
        }
    }
    

    更多信息here

    【讨论】:

      猜你喜欢
      • 2017-07-05
      • 1970-01-01
      • 1970-01-01
      • 2021-10-28
      • 2019-03-19
      • 1970-01-01
      • 2016-02-19
      • 1970-01-01
      • 2011-09-03
      相关资源
      最近更新 更多