Consider app.gradle
includes the following:
defaultConfig {
versionName "2.1.6"
}
debug {
debuggable true
versionNameSuffix "-debug"
}
Is it possible to get the version name without the suffix? When using PackageInfo pInfo = applicationContext.getPackageManager().getPackageInfo(applicationContext.getPackageName(), 0);
pInfo.versionName
returns 2.1.6-debug
is there a way to get only 2.1.6
without doing some string or regex matching.
Thank you!
I would do it using generated BuildConfig
:
Gradle
defaultConfig {
def version = "2.1.6"
versionName version
buildConfigField "String", "VERSION", "\"$version\""
}
Java
String version = BuildConfig.VERSION;
Question is old, but it might help someone - I have looked for something similar recently and used this:
debug{
buildConfigField "String", "APP_VER", "\"" + android.defaultConfig.versionName + "\""
}
OR for all buidTypes
buildTypes.each {
it.buildConfigField "String", "APP_VER", "\"" + android.defaultConfig.versionName + "\""
}
OR for all app variants:
applicationVariants.all { variant ->
variant.buildConfigField "String", "APP_VER", "\"" + android.defaultConfig.versionName + "\""
}
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