nashcft's blog

時々何か書く。

Android Gradle Plugin 4.1.0 から library module の BuildConfig に VERSION_CODE と VERSION_NAME が生えなくなりそう (なった)

Android Gradle Plugin 4.0.0 までは library module にも生えていた BuildConfig.VERSION_CODEBuildConfig.VERSION_NAME が 4.1.0-alpha05 から生えなくなってた

issuetracker: https://issuetracker.google.com/issues/154275579

Library module にとっては不要でしょ、とのこと

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.

AGP 4.1.0-beta01 で試しても同様だった

現在 library module の build.gradleversionCodeversionName を設定して、その module の BuildConfig からバージョン情報にアクセスしているようなアプリはDIでバージョン情報を使うもの/取得できるものを app から配るようにしないとダメそう

追記 (2020-10-13)

4.1.0 stable 出ました

https://developer.android.com/studio/releases/gradle-plugin?buildsystem=ndk-build#4-1-0

記述はないけど上記のままっぽいです 書いてあったわ
アプリの構造や設計によってやりようは色々ですが、大雑把には

  • DI で app module の BuildConfig へのプロキシを配る
  • 自分のアプリの PackageInfo から取得する
  • buildConfigField でバージョン情報を設定する

辺りになるんじゃないでしょうか