Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set different version number in android build types?

I need to set two different android build types i.e. staging and release.

 defaultConfig {
    applicationId "com.app.testing"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}

release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        buildConfigField "String", "SERVER_URL", '"http://testing.com"'
        }

dev {
        applicationIdSuffix  ".dev"
        buildConfigField "String", "SERVER_URL", '"http://testing.com"'
    }

Now I want to add versionName for each build type. How can I do that?

Edit

  productFlavors{
   release {
        versionname = "1.0"
   }

   dev{
       versionname = "1.0"
   }
}
like image 609
Amit Pal Avatar asked Feb 16 '16 08:02

Amit Pal


People also ask

How do I change my build tool version?

The Build Tools version of your project is (by default) specified in a build. gradle file, most likely in the app sub directory. Open the file and change/specify the Build Tools version you want to use by adding/changing a buildToolsVersion property to the android section: android { buildToolsVersion "24.0.

What is the difference between version name and version code?

The version code is an incremental integer value that represents the version of the application code. The version name is a string value that represents the “friendly” version name displayed to the users. Save this answer.


2 Answers

You can also use different version names for each build type without using flavors

In your app-module build.gradle:

  defaultConfig {
      ...
      versionName ""
  }
      ...
  buildTypes {

      debug {
          ...
          versionNameSuffix 'debug-version-1'
          ...
      }

      release {
          ...
          versionNameSuffix 'version 1'
          ...
      }


  }

versionName "" did the trick.

like image 112
Oleksiy Yudkin Avatar answered Oct 20 '22 04:10

Oleksiy Yudkin


You can use productFlavors like below:

productFlavors
{
   test
   {
     applicationId 'com.example.test'
     versionName '1.0.0.test'
     versionCode 1
   }

   product
   {
     applicationId 'com.example.product'
     versionName '1.0.0.product'
     versionCode 1
   }
}

You can define it under your default config. You can change from build variants. You can combine your build types with flavors.

Good luck.

like image 4
savepopulation Avatar answered Oct 20 '22 03:10

savepopulation