1
我有一個Android gradle項目,我有兩個buildTypes:QA和prod。我想根據構建類型更改.properties文件中的屬性。我也想根據buildType更改settings.gradle文件中的一個值。如果這是一個非常基本的問題,我對Android和Gradle很陌生,所以請原諒。更改.properties文件和基於buildType的android項目中的settings.gradle文件
這是我的屬性文件:
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 {
....
}
我不認爲你可以做到這一點。你想實現什麼? –
@GabrieleMariotti我想根據buildType加載不同的屬性。例如。如果buildType爲QA,則environment_name = qa,如果buildType爲prod,則在.properties文件中使用environment_name = prod。 – eureka19
在你的buildType中定義一個變量,或者簡單地在你的中使用不同的屬性(不是值)。屬性文件。 –