【问题标题】:gradle: execute code depending on the build type (or variant)gradle:根据构建类型(或变体)执行代码
【发布时间】:2013-10-14 21:34:31
【问题描述】:

我想根据构建类型(发布、调试)执行一些代码。具体来说,我想根据构建类型更改 APK 名称......像这样,

if (buildType.name == 'release') {
  project.archiveBaseName = 'blah';
} else if (buildType.name == ...) {
  ...
}

但是,我不知道将这段代码放在哪里。我可以迭代构建类型,

android.buildTypes.each{ type ->
    print type.name
}

但这当然给了我所有的构建类型,而不是当前的构建类型。

【问题讨论】:

标签: android groovy gradle android-studio


【解决方案1】:

我想 buildTypes 是您需要的功能: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Types

android {
    buildTypes {
        debug {
            packageNameSuffix ".debug"
        }
    }
}

有帮助吗?

【讨论】:

    猜你喜欢
    • 2015-05-19
    • 2015-06-11
    • 2018-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多