Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable proguard in flavor

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?

like image 445
falsetto Avatar asked Oct 19 '22 13:10

falsetto


1 Answers

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
}
like image 162
M. Reza Nasirloo Avatar answered Oct 21 '22 06:10

M. Reza Nasirloo