gpt4 book ai didi

android - 根据buildType更改android项目中的.properties文件和settings.gradle文件

转载 作者:行者123 更新时间:2023-12-02 03:20:31 26 4
gpt4 key购买 nike

我有一个 android gradle 项目,其中有两个 buildType:QA 和 prod。我想根据构建类型更改 .properties 文件中的属性。我还想根据 buildType 更改 settings.gradle 文件中的值之一。我是 android 和 gradle 的新手,如果这是一个非常基本的问题,请原谅。

这是我的 .properties 文件:

build_number=3.1-SNAPSHOT
version_number=3.1.0
environment_name=prod //this needs to changed to environment_name=qa in qa environment

这是我的 settings.gradle 文件:

rootProject.name = 'tom-android-prod' //this needs to changed to rootProject.name = 'tom-android-qa' in qa environment

这是我的 build.gradle 文件:

apply plugin: 'com.android.application'

buildscript {
repositories {
jcenter()

}

dependencies {

classpath 'com.android.tools.build:gradle:1.3.1'

}
}


android {
compileSdkVersion 21
buildToolsVersion "21.1.0"

defaultConfig {
multiDexEnabled true
}

dexOptions {
javaMaxHeapSize "4g"
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}

configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}

}

dependencies {
....
}

最佳答案

我不太确定您对 environment_name 的目标是什么,因为它没有被使用,但假设您只需要为特定build设置一个变量,那么您可以这样做:

ext {
environment_name = null
}
android {
// other stuff...
buildTypes {
qa {
project.ext.environment_name = "qa"
}
prod {
project.ext.environment_name = "prod"
}
}
}

// later you can use the variable like this
println "Hello variable: $project.ext.environment_name"

使用 buildTypes 应该不需要修改 rootProject.name = 'tom-android'。或者您可以以相同的方式使用 productFlavors 闭包...取决于您要为每个构建配置明确指定的内容。

关于android - 根据buildType更改android项目中的.properties文件和settings.gradle文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33852529/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com