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?
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
}
Related
I have two different flavor's, RQT & PRD.
And for one of them, I want to disable proguard configuration (for RQT, disable proguard for both buildTypes).
Like add conditioning ? Is something like that is possible ?
android {
...
flavorDimensions("server")
productFlavors {
rqt {
dimension "server"
applicationIdSuffix ".rqt"
}
prd {
dimension "server"
applicationIdSuffix ".prd"
}
}
...
buildTypes {
debug {
(__if (flavor != RQT) then do proguard config...__)
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFile 'proguard-debug-project.txt'
}
release {
(__if (flavor != RQT) then do proguard config...__)
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFile 'proguard-release-project.txt'
}
}
...
}
You could create additional Build Types, e.g. debugNoProguard, releaseNoProguard, etc.
android {
variantFilter { variant ->
def needed = variant.name in [
'rqtDebugNoProguard',
'rqtReleaseNoProguard',
'prdDebug',
'prdRelease'
]
variant.setIgnore(!needed)
}
buildTypes {
debug {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFile 'proguard-debug-project.txt'
}
debugNoProguard {
debuggable true
minifyEnabled false
signingConfig signingConfigs.debug
}
....
}
}
Then instead of building rqtDebug you would build the variant rqtDebugNoProguard or prdDebugNoProguard when you wanted to run a debug build without ProGuard.
class ReleaseTask extends DefaultTask {
#TaskAction
def releaseTask() {
def android = project.extensions.android
android.applicationVariants.all { variant ->
def mergedFlavor = variant.getMergedFlavor()
mergedFlavor.manifestPlaceholders = [UMENG_APPKEY: '', UMENG_MESSAGE_SECRET: '']
variant.buildConfigField("boolean", "enableChangeEnvDialog", "false")
}
}
}
project.tasks.create("releaseTask", ReleaseTask)
the code above is my custom gradle task.
buildTypes {
release {
signingConfig signingConfigs.release
zipAlignEnabled true
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
manifestPlaceholders = [UMENG_APPKEY:'',UMENG_MESSAGE_SECRET:'']
}
}
this code is my buildType block configration.
Now my problem is when I build my release apk, I used
./gradlew clean releaseTask assembleRelease
but in the release apk I didn't get the placeHolder in task but the keys in buildType/release block. but the code
variant.buildConfigField("boolean", "enableChangeEnvDialog", "false")
was effected.
I want to know why , and how to code the task to make it correct.
anything will be helpful.
thanks
flavorDimensions 'publish', 'develop'
productFlavors {
live {
dimension 'publish'
}
dev {
dimension 'develop'
applicationIdSuffix ".dev"
}
}
buildTypes {
debug {
minifyEnabled false
shrinkResources false
zipAlignEnabled true
debuggable true
productFlavors.live.signingConfig buildSignConfig.debug
productFlavors.dev.signingConfig buildSignConfig.debug
}
release {
minifyEnabled true
shrinkResources true
zipAlignEnabled true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
productFlavors.live.signingConfig buildSignConfig.release
productFlavors.dev.signingConfig buildSignConfig.release
}
}
I have 2 library modules and in application gradle file, I have above flavorDomensions, productFlavors and buildTypes. This produces build variant incorrectly like liveDevDedug and liveDevRelease. What could be the possible errors? Using AS 3.0
I want to add an if or something similar to my gradle build script, that decides wether to sign my App with the Debug-Key or Release Key accodring to what buildType I'm using. I can't do that in the buildTypes section, because if have different release keys for my product flavours. I tried it with something like buildType.name, but gradle does not know this property.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.txt'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.txt'
}
}
signingConfigs {
app1 {
....
}
app2 {
....
}
}
productFlavors {
app1 {
applicationId "com.test.app1"
}
app2 {
applicationId "com.test.app2"
if (buildType.name == 'release'){
signingConfig signingConfigs.app2
}
}
}
Edit: Ok I managed to solve it via gradle.properties: I add a property and set it true or false in buildtypes, and an if in the productFlavour add the signConfig if true.
I use Logger library in my development, and I configure it in my Application class:
#Override
public void onCreate() {
super.onCreate();
sInstance = this;
Logger.init(BuildConfig.LOGGER_TAG_NAME)
//.setMethodCount(3) // default 2
//.hideThreadInfo() // default shown
.setLogLevel(LogLevel.NONE); // default LogLevel.FULL
LogLevel is an enum (in Logger library).
But I want automatically to set the log level according my gradle build type; to do something like that:
buildTypes {
debug {
debuggable true
buildConfigField "enum", "LOGGER_LEVEL", LogLevel.FULL
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "enum", "LOGGER_LEVEL", LogLevel.NONE
}
}
then:
Logger.init(BuildConfig.LOGGER_TAG_NAME)
//.setMethodCount(3) // default 2
//.hideThreadInfo() // default shown
.setLogLevel(BuildConfig.LOGGER_LEVEL); // default LogLevel.FULL
But it doesn't work:
Error:(31, 0) No such property: NONE for class: org.gradle.api.logging.LogLevel
It's the same with FULL enum value.
Thanks for your help guys !
You must include the package and class name in both, property type and value:
buildTypes {
debug {
debuggable true
buildConfigField "com.orhanobut.logger.LogLevel", "LOGGER_LEVEL", "com.orhanobut.logger.LogLevel.FULL"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "com.orhanobut.logger.LogLevel", "LOGGER_LEVEL", "com.orhanobut.logger.LogLevel.NONE"
}
}
To avoid having to repeat the package name and to make the lines shorter, you can define some variable, like:
def LogLevel = "com.orhanobut.logger.LogLevel"
buildTypes {
debug {
debuggable true
buildConfigField LogLevel, "LOGGER_LEVEL", "${LogLevel}.FULL"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField LogLevel, "LOGGER_LEVEL", "${LogLevel}.NONE"
}
}