How to change Android version and code version number?

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.


Solution 1:

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

Solution 2:

The easiest way to set the version in Android Studio:

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

Android Studio < 3.4:

  1. Choose tab 'Flavors'
  2. 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.

Solution 3:

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
}