Enable proguard in flavor
Asked Answered
R

1

6

I'm using TeamCity to build version of application and upload it to HockeyApp. I want to enable proguard only on specific flavor and when building is on teamcity and uploading on HockeyApp, is it possible? Right now I defined variable in gradle file:

def runProguard = false

and set it in my flavors to false or true and then in build type I have:

if (project.hasProperty('teamcity') && runProguard.toBoolean()) {
    minifyEnabled true
  } else {
    minifyEnabled false
}

but it doesn't work on teamcity and I have version without proguard on HockeyApp. How to fix it? Is it another way to do it for example defining gradle task with enabled proguard?

Riata answered 11/3, 2016 at 10:44 Comment(3)
Do you run a debug or release build and do you have the second snippet in the buildTypes {…} closure or inside one of the debug { … } or release { … } ? To my knowledge it is only possible to call minifyEnabled directly in a build type.Perni
yes, this if statement is in debug buildTypeRiata
can you drop complete gradle file its better for understandingSkeg
I
4

You should do something like this to achieve what you want:

android {

buildTypes {
    debug {
        minifyEnabled false
        shrinkResources false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-debug.pro'
    }
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    mock {
        initWith(buildTypes.release)
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

productFlavors {
    pro {
        applicationId = 'com.example.app.pro'
    }

    free {
        applicationId = 'com.example.app.free'
    }
}

Also you can set some environment variable in teamcity and check if the build is happening on ci or it's on local machine:

if (!System.getenv("CI")) {
    //do something on local machine
} else {
    // do something on ci server
}
Ilocano answered 16/3, 2016 at 11:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.