最近升級AS 更新到4.1 Canary5+ ,發現庫工程BuildConfig.java 沒有VERSION_CODE和VERSION_NAME.
找了好多資料,最後在https://issuetracker.google.com/issues/154275579#comment3發現問題原因,並且標爲不予修復。
Version Code mean nothing for Libraries. It's actually potentially confusing as one might expect that the BuildConfig.VERSION_NAME of a library is set to the version name of the app but this was never the case. For these reasons, it's better to not include it in library modules.
大致意思是:"Version Code 在庫模塊中不代表任何意義。它還容易讓人混淆以爲把庫模塊的versoin_name是App的version_name. 基於這些原因,它最好不應該被包含再庫模塊中"
如果我還想在庫模塊中繼續使用VERSION_CODE、VERSION_NAME,那有沒有不解決方案呢?
當然還有的。
比如可以再build.gradle中再把VERSION_CODE,VERSION_NAME定義回來。
debug {
buildConfigField "String", "VERSION_NAME", "\"1.2.0\""
buildConfigField "int", "VERSION_CODE", "2"
}
release {
buildConfigField "String", "VERSION_NAME", "\"1.2.0\""
buildConfigField "int", "VERSION_CODE", "2"
}