How to set a different version number in Android build types?

I need to install two different build types for Android, i.e. stagingand 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 versionNamefor each type of assembly. How can i do this?

Edit

  productFlavors{
   release {
        versionname = "1.0"
   }

   dev{
       versionname = "1.0"
   }
}
+4
source share
4 answers

You can use productFlavors as shown 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 in your default configuration. You can change the build options. You can combine your build types with aromas.

Good luck.

+4
source

Version code may be in lower versions, for example:

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

3 , . 2 / , - , 1 .

, .

0

app-module build.gradle:

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

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

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


  }

versionName "" .

0

Android, .. .

buildTypes

, buildTypes: "release" "dev".

Now I want to add the name versionName for each type of assembly. How can i do this?

Iteration through buildTypes

A cleaner and more programmatic way to determine the versionName name (or any other defaultConfig parameter) for different types of buildTypes is to iterate through all the application options and perform a specific action for your buildTypes using if statements:

android {
   ...
   defaultConfig {
      ...
      applicationVariants.all { variant ->
         if(variant.buildType.name == "release") {
            //Release
            versionName "1.2.3"
         } else if(variant.buildType.name == "dev") {
            //Dev
            versionName "3.2.1"
         }
      }
   }
}
-1
source

Source: https://habr.com/ru/post/1628941/


All Articles