1

It appears that Android Studio 2.2 Preview 4 substitutes "INSTANT_RUN" for the versionName in PackageInfo rather than what has been put in the manifest. Is there any other way of seeing what is in versionName in the manifest? The code I am using is:

gstrVersion = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
jrisch
  • 132
  • 1
  • 9
  • You could try disabling Instant Run. – CommonsWare Jun 29 '16 at 11:52
  • Thanks, but that doesn't really answer the question. I'm asking if there is an alternative way to the code I posted to see the versionName, not to limit the IDE functionality so my code works. – jrisch Jun 30 '16 at 20:39
  • Try `BuildConfig.VERSION_NAME`. As a bonus, since that's just a constant, it will be faster and use less memory. However, I don't know if that too gets mangled by Instant Run. – CommonsWare Jun 30 '16 at 20:40
  • Thanks again, @CommonsWare, but it appears Instant Run mangles that as well, or rather both methods probably draw on the same base. – jrisch Jun 30 '16 at 21:19
  • 1
    That's surprising. If nothing else, you can do it manually, adding your own `buildConfigField` that you populate in `build.gradle` with the same value as you use for `versionName`. Or, depending on where you need the value, use `resValue` to add a string resource with the version name. – CommonsWare Jun 30 '16 at 21:29

1 Answers1

0

To answer your question,

No, there is no other way to get version name from manifest.

BUT Try

As commented by Sir CommansWare

you should disable INSTANT RUN,

File → Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run.

Check this answer for more details

Community
  • 1
  • 1
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
  • Thanks, but that doesn't really answer the question. I'm asking if there is an alternative way to the code I posted to see the versionName, not to limit the IDE functionality so my code works. – jrisch Jun 30 '16 at 20:38