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
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.
I have two build variants uat and prod.
In uat I am making debuggable to true while in prod I am making it to false.
But app is still showing in debuggable after making it to false.
It's happen only in case of emulator.
following is code in my app graddle file
buildTypes {
android.variantFilter { variant ->
if (variant.buildType.name.equals('release') || variant.buildType.name.equals('debug')) {
variant.setIgnore(true);
}
}
uat {
debuggable true
signingConfig signingConfigs.uat
minifyEnabled false
//zipAlignEnabled true
applicationIdSuffix ".uat"
buildConfigField "String", "URL_ENDPOINT", "\"http://your.development.endpoint.com/\""
}
prod {
debuggable false
jniDebuggable false
signingConfig signingConfigs.prod
renderscriptDebuggable false
minifyEnabled false
// zipAlignEnabled true
applicationIdSuffix ".prod"
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
I have my gradle file as below, where I sign my app as Debug in debug build, and Release in release build. It has two flavor i.e. Develop and Production.
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
productFlavors {
develop {
// Do something
}
production {
// Do something
}
}
However, I'm thinking of signing as Debug for Develop flavor (release) as well. How could I achieve that (i.e. access the flavor type variable in the buildType)?
As I understand your question you want something like this:
developDebug: signingConfigs.debug
productionDebug: signingConfigs.debug
developRelease: signingConfigs.debug
productionRelease: signingConfigs.release
You can achieve it this way:
android {
productFlavors {
develop {
// Do something
}
production {
// Do something
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
// Make an unfinished release build type
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
// Finish the release build type flavor specific
def runTasks = gradle.startParameter.taskNames.toString().toLowerCase()
if (runTasks.contains("develop")) {
release {
signingConfig signingConfigs.debug
}
} else if (runTasks.contains("production")) {
release {
signingConfig signingConfigs.release
}
}
}
}
Edit: I think this might be a cleaner solution
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
release-develop {
initWith buildTypes.release
signingConfig signingConfigs.debug
}
}
You could also use:
productFlavors.develop.signingConfig signingConfigs.debug
inside of your release build type.
Original Answer:
Something like this should do the trick.
The hierarchy goes buildTypes -> defaultConfig -> productFlavors
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
defaultConfig {
signingConfig signingConfigs.release
}
productFlavors {
develop {
signingConfig signingConfigs.debug
// Do something
}
production {
// Do something
}
}
developDebug: signed with debug key from debug variant
developRelease: signed with debug key in develop flavor
productionDebug: signed with debug key from debug variant
productionRelease: signed with release key from defaultConfig since its not defined in release variant.
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
}
I read the "Build System" section of the android docs: http://developer.android.com/sdk/installing/studio-build.html
So a build variant is composed of a product_flavor-build_type. I have this build.gradle:
buildTypes {
debug {
applicationIdSuffix '.debug'
debuggable true
minifyEnabled !skipProguard
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.debug
zipAlignEnabled false
}
debugtest {
// unit tests
applicationIdSuffix '.test'
debuggable true
minifyEnabled false
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.debug
zipAlignEnabled false
}
release {
minifyEnabled true
shrinkResources true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.release
}
}
productFlavors {
internal {
applicationId "${project.applicationId}.internal"
buildConfigField 'boolean', 'EXPERIMENTAL', 'true'
buildConfigField 'boolean', 'FAKE_HTTP_RESPONSE', 'false'
}
production {
applicationId project.applicationId
buildConfigField 'boolean', 'EXPERIMENTAL', 'false'
buildConfigField 'boolean', 'FAKE_HTTP_RESPONSE', 'false'
}
automation {
applicationId "${project.applicationId}.automation"
buildConfigField 'boolean', 'EXPERIMENTAL', 'true'
buildConfigField 'boolean', 'FAKE_HTTP_RESPONSE', 'true'
}
}
I'd like to create mobile-debug-automation-unaligned.apk so that I can use the "FAKE_HTTP_RESPONSE" BuildConfig variable in a dagger module.
But when I click on "Build Variants" in Android Studio I see one build variant-"internalDebug". I expected to see 9 build variants(buildType * productFlavor).
Looking in my project directories, I see the following apks:
MY_APP/mobile: mobile-release.apk, mobile-debug-unaligned.apk
MY_APP/mobile/build/outputs/apk: mobile-internal-debug-unaligned.apk
How do I generate my new "automation" apk?
Plz click on it to change:
If it doesn't work, rebuild your project.