Free Android app covering all aspects of addiction, including prevention and treatment

Android app ApplicationId, versionName and versionCode explained

  • Written by  clive

Your Android app’s versionName, versionCode and ApplicationID made easy

Android applicationId, versionCode and versionName icon

 

So what’s an Application ID?

Each app has a unique id which looks something like this com.example.myApp. No two apps can have the same id.

The application id matches the Java-style package name that you used when you created a new project in Android Studio.

The application id identifies the app on a device as well as in the Google Play store. Never change the app id once you have published the app in the play store.

Can I change the application id and package name?

Once you have finished setting up your project in Android Studio, the application id and package name are independent of each other and you can change either without affecting the other.

Why would I want to change the application id?

You may want to change your app’s application id:

  • For different build variants – for example, you may have a free and a pay version of the same app. They each will need a unique id when you publish them in the app store
  • For testing – it’s not necessary but you can change the app’s id for testing if you wish

Be aware though that you should not change your application id once you have published your app.

Can I change the package name?

Yes you can.

The package name matches the application id by default but you can change it.

Be aware that the package name should always match the package attribute as depicted in the AndroidManifest.xml file.

Use Android Studio’s tools to rename and refactor your packages so that the package name and package attribute will automatically be synced for you.

Although you can have a different name for the manifest package attribute and the applicationId, Android Studio uses the applicationId in the final build and copies it to the final APK’s manifest package attribute.

The Google Play Store and the Android platform both look at the AndroidManifest.xml package attribute to identify your app.

See the documentation for more on the application id and package name

Versioning your app

Versioning your app refers to giving it a version name and a version code.

Why Version your app?

  • Users want to know which version of your app is installed and what upgrades are available
  • Other app’s may need to know your app’s version to determine compatibility and identify dependencies
  • Publishers (like Google’s Play Store) need to know your app’s version so that they can display it to their users

Where do I set the Version information?

  • In the manifest – it’s advisable to not do it here but in the Gradle Build file
  • In the Gradle Build file – these settings will override the manifest settings

There are two settings for versioning your app. You should set both:

  • versionCode
  • versionName

So what’s the difference between versionCode and versionName?

versionCode

An integer used to display whether one version of your app is more recent than another. Higher numbers indicate a more recent version.

Users don’t see this value.

Set it to any number and make sure to increase this value with each new release.

versionName

A string representing the version number which is then shown to the user. This is its only purpose.

Note that when using Instant Run Android Studio sets the versionCode to MAXINT and the versionName to “INSTANTRUN”.

So where do I set these values?

Open up your build.gradle(Module:app) file:

Android applicationId, versionCode and versionName build.gradle

Open up your app’s build.gradle(Module:app) file

Then add the settings in the defaultConfig{} block which looks something like this:

Android applicationId, versionCode and versionName defaultConfig

Set your app’s versionCode and versionName in the build.gradle file’s defaultConfig{} block

How do I get the versionCode and versionName values programmatically?

Here are two possibilities.

  1. By first getting the package info, like this:

Android applicationId, versionCode and versionName packageInfo

Call getPackageManager() and then getPackageInfo() to get the package information for your app. You can then get the versionCode and versionName out of the package info

  1. If you’re using Android Studio, by using the BuildConfig for your package, like this:

Android applicationId, versionCode and versionName buildConfig

Make sure that you import the BuildConfig for your app

See the documentation for more on Versioning your app.

Related items