230

How to change Android version and code version number Android Studio? I want to change apk file (app) on Google Play and I need to change Android version and code version number. I tried with this in AndroidManifest.xml file in Android Studio:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bestsoftcorporation.circle.app"
android:versionCode="101"
android:versionName="2.0">

But it does not work. When I tried to publish it on Google Play it display that I must to change Android version name and code.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Marko Stojkovic
  • 3,255
  • 4
  • 19
  • 20

13 Answers13

427

Go in the build.gradle and set the version code and name inside the defaultConfig element

defaultConfig {
    minSdkVersion 9
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}

screenshot

Ajay S
  • 48,003
  • 27
  • 91
  • 111
  • 2
    Is there a way to access the versionname in Java? – Mark Molina Jun 13 '14 at 09:33
  • Do we also have to change the xml verion if only java files have been updated ?-> ?xml version="1.0" encoding="utf-8"?> – Abhinav Arora Jul 07 '14 at 09:06
  • 2
    Make sure to clean the project after changing the version or it may not show up in the APK. – RhodanV5500 Oct 01 '14 at 08:31
  • 7
    It solved my issue too. However, I really really hate,hate,hhhaaate when you have million different places where to change a variable and just one of them is the right one, like in this case!!!! – Gianluca Ghettini Jul 17 '15 at 08:38
  • Just to mention that my project (Imported from Eclipse) didn't have the relevent lines in the build.gradle. Using the method below suggested by Ivo Stoyanov worked and added the lines. – s1ni5t3r Apr 10 '16 at 10:24
  • 1
    It's pretty annoying, since this setting was just for a single App, why not keep it in APP's manifest.xml ? Google did this for no reason...... – RRTW Nov 14 '17 at 02:39
  • @RRTW True mate, it's fricking annoying to scrape Documentation when this one line is all it takes ... – Jitin Jan 12 '21 at 11:44
89

The easiest way to set the version in Android Studio:

1. Press SHIFT+CTRL+ALT+S (or File -> Project Structure)

Android Studio < 3.4:

  1. Choose app (from left panel).
  2. Choose tab 'Flavors'
  3. The last two fields are 'Version Code' and 'Version Name'

Android Studio >= 3.4:

  1. Choose 'Modules' in the left panel.
  2. Choose 'app' in middle panel.
  3. Choose 'Default Config' tab in the right panel.
  4. Scroll down to see and edit 'Version Code' and 'Version Name' fields.
scsfdev
  • 345
  • 1
  • 5
  • 14
Ivo Stoyanov
  • 16,256
  • 8
  • 62
  • 65
  • 11
    FYI: File -> Project Structure -> Choose tab 'Flavors' Thank you @Ivo Stoyanov – Ego Slayer Mar 24 '15 at 09:40
  • I face very strange issue. I change versionName from build.gradle file but it was not updated in BuildConfig file and so when I generate apk, it shows wrong versionName. Then I edit versionName from flavors, then it starts working. Thank you! – Smeet Feb 16 '17 at 14:28
  • 2
    Note: This no longer works as of Android Studio 3.4 – Adjwilley May 03 '19 at 01:39
24

You can define your versionName and versionCode in your module's build.gradle file like this :

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    .... //Other Configuration
}
Piyush Agarwal
  • 25,608
  • 8
  • 98
  • 111
13

Press Ctrl+Alt+Shift+S in android studio or go to File > Project Structure...

Select app on left side and select Flavors tab on right side on default config change version code, name and etc... enter image description here

Axifive
  • 1,159
  • 2
  • 19
  • 31
Masoud.Ebrahimi
  • 309
  • 3
  • 4
5

You can manage your application versioning wisely by using the Advanced Build Version Plugin for Gradle.

You just need to include the plugin in yout build.gradle:

buildscript {
  repositories {
      jcenter()
  }

  dependencies {
      classpath 'org.moallemi.gradle.advanced-build-version:gradle-plugin:1.5.0'
  }
}

apply plugin: 'org.moallemi.advanced-build-version'

And then you can use the versioning functions (and, obviously, customize them):

advancedVersioning {
    nameOptions { }
    codeOptions { }
    outputOptions { }
}

def appVersionName = advancedVersioning.versionName
def appVersionCode = advancedVersioning.versionCode

For more information, take a look at the official documentation.

bonnyz
  • 13,458
  • 5
  • 46
  • 70
4

The official documentation on this is here.

The short answer is do it in Gradle not the manifest, Gradle overwrites the manifest.

The File | Project Structure | Modules | Default Config answer given above just updates Gradle via a UI rather than by directly editing XML.

How to update the Gradle XML

The longer answer is:

If your app defines the app version directly in the element, the version values in the Gradle build file will override the settings in the manifest. Additionally, defining these settings in the Gradle build files allows you to specify different values for different versions of your app. For greater flexibility and to avoid potential overwriting when the manifest is merged, you should remove these attributes from the element and define your version settings in the Gradle build files instead.

Mark Kortink
  • 1,770
  • 4
  • 21
  • 36
3

Open your build.gradle file and make sure you have versionCode and versionName inside defaultConfig element. If not, add them. Refer to this link for more details.

Egor
  • 39,695
  • 10
  • 113
  • 130
2

Go in the build.gradle and set the version code and name inside the defaultConfig element

defaultConfig { minSdkVersion 9 targetSdkVersion 19 versionCode 1 versionName "1.0" }

rajlaxmi_jagdale
  • 1,370
  • 15
  • 16
1

After updating the manifest file, instead of building your project, go to command line and reach the path ...bld\Debug\platforms\android. Run the command "ant release". Your new release.apk file will have a new version code.

Vishwani
  • 623
  • 6
  • 8
1

I didn't get the other answers to work in Android Studio 1.4. But this worked: click on your app name to the left below the main ribbon. It will show a list of files. Open AndroidManifest.xml and change the version code and version number there.

1

Android version and code version number change on Android Studio >= 3.6:

Two ways to achieve this:

  1. Direct on the Android project by Open Flutter project and modify the file

    local.properties

change the following values. Example:

flutter.buildMode=release
flutter.versionName=3.0.0
flutter.sdk=C\:\\src\\flutter
sdk.dir=C\:\\Users\\vgonza\\AppData\\Local\\Android\\sdk
flutter.versionCode=30
  1. Open pubspec.yaml

Change the

version: 2.0.0+8

Meaning: The version name is 2.0.0 The version code is 8

See example by Suragch in:

How to set build and version number of Flutter app

Val
  • 101
  • 1
  • 10
0

You can easily auto increase versionName and versionCode programmatically.

For Android add this to your gradle script and also create a file version.properties with VERSION_CODE=555

android {
        compileSdkVersion 30
        buildToolsVersion "30.0.3"
    
        def versionPropsFile = file('version.properties')
        if (versionPropsFile.canRead()) {
            def Properties versionProps = new Properties()
    
            versionProps.load(new FileInputStream(versionPropsFile))
    
            def code = versionProps['VERSION_CODE'].toInteger() + 1
    
            versionProps['VERSION_CODE'] = code.toString()
            versionProps.store(versionPropsFile.newWriter(), null)
    
    
            defaultConfig {
                applicationId "app.umanusorn.playground"
                minSdkVersion 29
                targetSdkVersion 30
                versionCode code
                versionName code.toString()
UmAnusorn
  • 10,420
  • 10
  • 72
  • 100
0

To change version of your app you have to change both of versionCode and versionName in the following files:

build.gradle:

defaultConfig {
        applicationId "com.pms.app"
        minSdk 30
        targetSdk 31
        versionCode 2
        versionName "1.0.5-beta"
    }

app_config.json:

{
  "minSdkVersion": 21.0,
  "viewBindingEnabled": false,
............
  "useR8": false,
  "targetSdkVersion": 30.0,
  "versionName": "1.0.5-beta",
  "versionCode": 2.0,
  "zipAlignEnabled": false
}

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.pms.app"
    android:versionCode="2"
    android:versionName="1.0.5-beta">
Anti Atlas Dev
  • 416
  • 1
  • 4
  • 15