What Do I Do To Get Compatibility Patch Download Off My Android Phone

Active10 days ago

I need to figure out how to get or make a build number for my Android application. I need the build number to display in the UI.

Do I have to do something with AndroidManifest.xml?

8 things you should know about Apple Music for Android. With a list of choices installed on my phone. Apple Music isn't on that list and if I answer with 'Apple Music' Google doesn't.

Peter O.
22.1k9 gold badges60 silver badges71 bronze badges
Fahad Ali ShaikhFahad Ali Shaikh
5,8953 gold badges11 silver badges4 bronze badges

28 Answers

Use:

And you can get the version code by using this

Gastón Saillén
4,7344 gold badges14 silver badges36 bronze badges
plus-plus-
30.4k12 gold badges48 silver badges69 bronze badges

If you're using the Gradle plugin/Android Studio, as of version 0.7.0, version code and version name are available statically in BuildConfig. Make sure you import your app's package, and not another BuildConfig:

No Context object needed!

Also make sure to specify them in your build.gradle file instead of the AndroidManifest.xml.

Sam DozorSam Dozor
32.8k6 gold badges36 silver badges42 bronze badges

Slightly shorter version if you just want the version name.

Xavi
16.3k12 gold badges65 silver badges60 bronze badges
scottyabscottyab
18.3k11 gold badges82 silver badges95 bronze badges

There are two parts you need:android:versionCode android:versionName

versionCode is a number, and every version of the app you submit to the Market needs to have a higher number then the last.

VersionName is a string, and can be anything you want it to be. This is where you define your app as '1.0' or '2.5' or '2 Alpha EXTREME!' or whatever.

Example:

Kotlin:

Java:

MerkidemisMerkidemis
1,9272 gold badges13 silver badges24 bronze badges

Using Gradle and BuildConfig

Getting the VERSION_NAME from BuildConfig

Yep, it's that easy now.

Is It Returning an Empty String for VERSION_NAME?

If you're getting a empty string for BuildConfig.VERSION_NAME then read on.

I kept getting an empty string for BuildConfig.VERSION_NAME because I wasn't setting the versionName in my Grade build file (I migrated from ANT to Gradle). So, here are instructions for ensuring you're setting your VERSION_NAME via Gradle.

build.gradle

Note: This is from the masterful Jake Wharton.

Removing versionName and versionCode from AndroidManifest.xml

And since you've set the versionName and versionCode in the build.gradle file now, you can also remove them from your AndroidManifest.xml file, if they are there.

Joshua PinterJoshua Pinter
27.1k9 gold badges156 silver badges178 bronze badges

Here is a clean solution, based on the solution of scottyab (edited by Xavi). It shows how to get the context first, if it's not provided by your method. Furthermore it uses multiple lines instead of calling multiple methods per line. This makes it easier when you have to debug your application.

Now that you received the version name in the String myVersionName, you can set it to a TextView or whatever you like..

MichaelMichael
2,9274 gold badges24 silver badges39 bronze badges
Velayutham MVelayutham M

If you're using PhoneGap, then create a custom PhoneGap plugin:

Create a new class in your app's package:

In the plugins.xml, add the following line:

In your deviceready event, add the following code:

Then, you can get the versionName attribute by doing:

Derived from here and here.

Sean HallSean Hall
6,0662 gold badges22 silver badges39 bronze badges

For xamarin users, use this code to get version name and code

1) Version Name:

2) Version Code:

What Do I Do To Get Compatibility Patch Download Off My Android PhoneRKRK
1,2522 gold badges12 silver badges16 bronze badges
Tushar patelTushar patel
2,1632 gold badges17 silver badges23 bronze badges

If you want to use it on xml then add below line on your gradle file:

And then use it on your xml like this:

Irfan RazaIrfan Raza
2,1711 gold badge16 silver badges26 bronze badges
Pratik Butani AndroidDevPratik Butani AndroidDev
33.3k28 gold badges155 silver badges293 bronze badges
Kevin Wallis
3,2053 gold badges18 silver badges35 bronze badges
Gevaria PurvaGevaria Purva

To get the build code which is used to identify the apk by its version code . Version code is used to detext the actual build configuraion at the time of database upgrade, publish etc.

int versionCode = BuildConfig.VERSION_CODE;

What Do I Do To Get Compatibility Patch Download Off My Android Phone Free

Version name is used to shoe the users pr the developers of the developmemt sequence.You can add any kind of version name as you want

String versionName = BuildConfig.VERSION_NAME;

Rohit PatilRohit Patil
Shubham GuptaShubham Gupta

There are some ways to get versionCode and versionName programmatically.

  1. Get version from PackageManager. This is the best way for most cases.
  1. Get it from generated BuildConfig.java. But notice, that if you'll access this values in library it will return library version, not apps one, that uses this library. So use only in non-library projects!

There are some details, except of using second way in library project. In new android gradle plugin (3.0.0+) some functionalities removed. So, for now, i.e. setting different version for different flavors not working correct.

Incorrect way:

Code above will correctly set values in BuildConfig, but from PackageManager you'll receive 0 and null if you didn't set version in default configuration. So your app will have 0 version code on device.

There is a workaround - set version for output apk file manually:

mohaxmohax
2,6622 gold badges23 silver badges60 bronze badges

No,you don't need to do anything with AndroidManifest.xml

Basically your app's version name & version code inside app level gradle file, under defaultConfig tag:

Note: When you wish to upload app in playstore can give any name as version name but version code have to be different than current version code if this app already in play store.

Simply use the following code snippet to get version code & version name from anywhere in your app:

Monir ZzamanMonir Zzaman

for Api 28 the PackageInfo.versionCode is deprecated so use this code below:

Amir jodatAmir jodat

This code was mentioned above in pieces but here it is again all included. You need a try/catch block because it may throw a 'NameNotFoundException'.

I hope this simplifies things for someone down the road. :)

Jeff.HJeff.H

Someone who does’t need BuildConfig info for application's UI however wants to use these info for setting a CI job configuration or others, like me.

There is a automatically generated file, BuildConfig.java, under your project directory as long as you build your project successfully.

{WORKSPACE}/build/generated/source/buildConfig/{debug|release}/{PACKAGE}/BuildConfig.java

Split information you need by python script or other tools. Here’s an example:

Please excuse my limited English ability, but hope this helps.

JasonChiuJasonChiu
Durul DalkanatDurul Dalkanat
5,5163 gold badges28 silver badges33 bronze badges
Mr.Sandy
3,4113 gold badges26 silver badges50 bronze badges
Heenali LakhaniHeenali Lakhani
meduvigomeduvigo
Atif Mahmood

What Do I Do To Get Compatibility Patch Download Off My Android Phone Number

Atif Mahmood
6,3222 gold badges30 silver badges39 bronze badges
Sapphire91140Sapphire91140
janardhanjanardhan

What Do I Do To Get Compatibility Patch Download Off My Android Phone Download

As I had to get only version code and check whether app is updated or not, if yes, I had to launch the playstore to get updated one. I did this way.

Then I saved version code using shared preference by creating an util class.

Ishwor KhanalIshwor Khanal
Shanmugavel GKShanmugavel GK

Useful for build systems: there is a file generated with your apk called output.json which contains an array of information for each generated APK, including the versionName and versionCode.

eg

TomTom

What Do I Do To Get Compatibility Patch Download Off My Android Phone App

protected by CommunityMar 23 '18 at 15:05

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged androidandroid-emulatorandroid-manifest or ask your own question.