Android Studio 4.1 Canary 5+ Library Module BuildConfig 找不到符號 VERSION_CODE VERSION_NAME

最近升級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"
        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章