在開發的時候遇到服務器配置的問題,想在測試環境和開發環境中配置兩套不同的服務器參數,于是想到在gradle中使用buildConfigField來配置, 在library中讀取
debug {
debuggable true
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "SERVER_CONFIG", "\"apptest.properties\""
}
release {
signingConfig signingConfigs.debug
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "SERVER_CONFIG", "\"app.properties\""
}
但無論如何在調試過程中,讀取到SERVER_CONFIG的值都是release里的值。上stackoverflow一查,原來這是已知bug,并且過了好久都沒見修復。。。。
詳情見這個鏈接stackoverflow
This is expected behavior for this.
Library projects only publish their release variants for consumption by other projects or modules.
We're working at fixing this but this is non trivial and requires a significant amount of work.
You can track the issue at https://code.google.com/p/android/issues/detail?id=52962