Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different code in different build variant

I have two build variants in my app, one is an standard app edition and the second one is a customization app.

productFlavors {
        customConfig {
            minSdkVersion 14
            applicationId 'es.com.custom'
            targetSdkVersion 22
            versionCode 3
            versionName '3.0.0'
        }
        standard {
            minSdkVersion 14
            applicationId 'es.com.standard'
            targetSdkVersion 22
            versionCode 3
            versionName '3.0.0'
        }

For the customization I have to implement new features, but just for the customization, so those new features will be not available on the standard version. I am not sure what i have to do.

1.- Two classes , one with the standard requirements and one with the custom requirements
2.- In the standard class do something like:

  if (getPackageName()==customConfig )
    // do the custom things
    else
    //do the standard things
like image 922
JoCuTo Avatar asked May 04 '17 08:05

JoCuTo


2 Answers

You must create source directories for each flavor. So you will be able to maintain a separate file for the specific flavor.

Please go through the link that will help you.

like image 111
N J Avatar answered Oct 19 '22 16:10

N J


Build variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Although you do not configure build variants directly, you do configure the build types and product flavors that form them.

 if(BuildConfig.Flavor.equals("customConfig")) 
    {

    }
  else
   {

   }

Read Building multiple flavors of an Android

like image 27
IntelliJ Amiya Avatar answered Oct 19 '22 16:10

IntelliJ Amiya