1

Gradle Play publisher lets you override the version name before publishing to the play store.

play {
// ...
  resolutionStrategy = "auto"
  outputProcessor { // this: ApkVariantOutput
    versionNameOverride = "$versionNameOverride.$versionCode"
}

}

Is it possible to use the value of versionNameOverride in Java Code? We display the version name in the about page of the app using the versionName attribute. GPP updates the versionNameOverride value so the play store listing shows the correct version number but the app's about page keeps showing a different version number that's based on versionName.

SUPERCILEX
  • 3,929
  • 4
  • 32
  • 61
Vivek Maskara
  • 1,073
  • 11
  • 29

1 Answers1

1

Using the versionNameOverride could be done like this:

outputProcessor { output ->
    output.versionNameOverride = output.versionNameOverride + "." + output.versionCode
    def versionPropertyFile = file "version.properties"
    def versionProperties = new Properties()
    versionProperties.setProperty('versionCode', "$output.versionCode")
    versionProperties.setProperty('versionName', output.versionNameOverride)
    versionPropertyFile.withWriter { versionProperties.store(it, "Generated by the outputProcessor for the play plugin during publishing.") }
}

But if you want to show the versionName in your app it would be easier to use

try {
    PackageInfo pInfo = 
context.getPackageManager().getPackageInfo(getPackageName(), 0);
    String version = pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
}

The reason why your app did show the wrong values might be that your app was using BuildConfig. But the versionCode and versionName there do not reflect what has been set through versionNameOverride, but those values from your build gradle.

tobltobs
  • 2,782
  • 1
  • 27
  • 33