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?

falsetto
  • 789
  • 2
  • 11
  • 35
  • 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. – Matthias Wenz Mar 11 '16 at 11:15
  • yes, this if statement is in debug buildType – falsetto Mar 11 '16 at 11:28
  • can you drop complete gradle file its better for understanding – Maheshwar Ligade Mar 15 '16 at 01:36

1 Answers1

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
}
M. Reza Nasirloo
  • 16,434
  • 2
  • 29
  • 41