I want to log and report (in errors) what version of my library is being used. How is it possible to programmatically read android.defaultConfig.versionName
from build.gradle of my library?
I have tried:
PackageInfo packageInfo = applicationContext.getPackageManager()
.getPackageInfo("com.my.library",0);`
Where com.my.library
is the package name of my library.
However, this results in a NameNotFoundException
.
Any ideas ?
You can access the version name of library projects using the library project's BuildConfig.VERSION_NAME
constant.
For example, you can get the version name of the v7 support library via android.support.v7.appcompat.BuildConfig.VERSION_NAME
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With