android-studio - 如何通过Android studio项目同步自定义编译参数?
问题描述
我项目中的一些参数需要在编译时传入。
所以我的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 将在配置您的项目时执行它。
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")
}
}
}
更多信息在这里
推荐阅读
- angular - 已关闭 - Angular Material Typography 无法正常工作
- dart - 如何用里面的所有内容替换括号?
- .net - 当前项目中的 WPF 动态资源
- flutter - 在颤振中为不同的班级提供不同的主题
- python - 带有反馈的自动启动 python 脚本
- python - 使用辅助 y 轴时共享 x 轴
- swift - 我可以将 Xcode 与 iPhone Simulator.app 一起安装在外部硬盘上吗?
- xpath - XPath 查询似乎在 Google 表格中不起作用
- python - 使用 SSH 命令在 python 中生成字典
- python - 查找单词的频率并绘制结果