Different code in another version of the assembly

I have two build options in my application, one is the standard version of the application, and the second is the configuration application.

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 customization, I have to implement new features, but only for customization, so these new features will not be available in the standard version. I'm not sure what to do.

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

  if (getPackageName()==customConfig )
    // do the custom things
    else
    //do the standard things
+4
source share
3 answers

Gradle , , . , .

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

    }
  else
   {

   }

Android

+2

. , .

, .

+2

. " " . " customConfig" ( gradle) , .

customConfig "res" ( , , ). "values". "values" . " values.xml" . values.xml :

<?xml version="1.0" encoding="utf-8"?>
<resources>
     <string name="custom_app_id">es.com.custom</string>s
</resources>

Now in your code you can check which variable you are in:

 if (getPackageName().equals(getString(R.string.custom_app_id)))// for custom
// do the custom things
else
//do the standard things

Hope this help!

+1
source

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


All Articles