Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obfuscate only one flavour

How would i go about obfuscating just one flavour.

Unfortunately flavour 2 relies on a module (jar) that uses some duplication of classes, and i cannot obfuscate it due to the way it is set up. (3rd party) So wish to skip obfuscating the flavour.

I do not seem able to define minifyENabled false in the flavours section, or add the flavour to the build section.

Note, there are actually 6 flavours in total. The desire is to pick and choose flavours that should be obfuscated

   buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    productFlavors {
        flavour1{
            applicationId "uk.co.company.flavour1"
        }
        flavour2{
            applicationId "uk.co.company.flavour2"
        }
   }
like image 866
IAmGroot Avatar asked Mar 02 '17 11:03

IAmGroot


People also ask

Is minifyEnabled true?

Code shrinking with R8 is enabled by default when you set the minifyEnabled property to true .

What is Android Flavour?

Android Product Flavors are used to create different app versions. App versions can be free or paid. They can have different themes and texts. They can use different environments or APIs. Let's assign two product flavors free and paid in our application.

Does ProGuard obfuscate package name?

Obfuscating package names myapplication. MyMain is the main application class that is kept by the configuration. All other class names can be obfuscated. Note that not all levels of obfuscation of package names may be acceptable for all code.


Video Answer


1 Answers

As long as there is not present minifyEnabled in ProductFlavor DSL object, then you have to create another buildType, e.g. releaseMinified along with standard release.

buildTypes {
    release {
        minifyEnabled false
    }
    releaseMinified {
        minifyEnabled true
    }
}

productFlavors {
    minifiableFlavor{}
    nonMinifiableFlavor{}
}

And enable this build type only for the flavor that needs that:

android.variantFilter { variant ->
    if (variant.buildType.name.equals('releaseMinified') && !variant.getFlavors().get(0).name.equals('nonMinifiableFlavor')) {
        variant.setIgnore(true);
    } else if (variant.buildType.name.equals('release') && variant.getFlavors().get(0).name.equals('nonMinifiableFlavor')){
        variant.setIgnore(true);
    }
}

Then you'll end up with:

Build types

like image 185
azizbekian Avatar answered Sep 21 '22 21:09

azizbekian