Search code examples
androidandroid-productflavors

MultiDex.install only on some product flavor


I need to call MultiDex.install inside "attachBaseContext" but only for debug builds and for a single flavor (api level < 21).
Currently i have in my build.gradle the dependencies like this:

debugCompile deps.support.multidex
icsCompile deps.support.multidex

What is the best way to call MultiDex.install for only these flavors?


Solution

  • Just check BuildConfig values in attachBaseContext:

    @Override
    protected void attachBaseContext(Context base) {
       super.attachBaseContext(base);
       if (BuildConfig.DEBUG || BuildConfig.FLAVOR.equals("flavorName")) {
          MultiDex.install(this);
       }
    }