15

I imported several eclipse projects to Android Studio (v1.1).

In the original Eclipse environment, they use Proguard for release mode.

In the Android Studio environment, this was translated to the following in the build.gradle script (by the import, not by me):

buildTypes {
    release {
        minifyEnabled true
        proguardFiles 'proguard.cfg'
    }
}

I understand that this means that "in release build, enable Proguard's minify, using proguard.cfg".

The problem, however, is that minify seems to be happening in non-release build (i.e. debug) as well!

How is this possible?

What is the default for minifyEnabled for debug build?


UPDATE 1: Thanks to the answer below, I now know that the default is false. Which means something else is building the various modules minified in debug build.

I am posting the entire build.gradle for one of the modules that get minified in debug build:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 8
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 8
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles 'proguard.cfg'
        }
    }
}

The entire build.gradle for the project itself (i.e. top level) is:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

I cannot spot here anything that could explain enforcing minify on a debug build.


UPDATE 2: Suspecting a mismatch between app's build (debug) and the modules on which it depends (release?), I also checked the Build Variant view on the the left panel. The all show debug unequivocally.


UPDATE 3: It appears that I hit a bug/limitation in Android-Gradle?

I truly need all modules built in debug mode when the app is built in debug mode.

Any ideas how I can solve this problem?

Community
  • 1
  • 1
ususer
  • 653
  • 1
  • 6
  • 14

2 Answers2

18

The default value for minifyEnabled is false for all build types, as @laalto answered.

However, currently (as of 2015-04-24), this is not true for multi-module projects, in which some modules (app included) are dependent on other modules. This is due to bug #52962 that causes build types to not propagate to libraries -- they're always built as RELEASE.

Suggestions to work around this bug or notifications of its fix are most welcome.

ususer
  • 653
  • 1
  • 6
  • 14
16

What is the default for minifyEnabled for debug build?

The default value for minifyEnabled is false for all build types. Reference.

The problem, however, is that minify seems to be happening in non-release build (i.e. debug) as well!

How is this possible?

Your debug build gets proguard treatment possibly by some other definition somewhere, or an external build script you're using.


In your updated question, you have a library project and an app project that uses a minified library even for debug builds. That's a "feature". For a solution, consider the following also mentioned in the issue report:

Build all variants of the library project by adding the following to its build.gradle:

android {
    publishNonDefault true
}

In the app project, choose the build type specific dependency with

dependencies {
    releaseCompile project(path: ':theotherproject', configuration: 'release')
    debugCompile project(path: ':theotherproject', configuration: 'debug')
}
Community
  • 1
  • 1
laalto
  • 150,114
  • 66
  • 286
  • 303
  • 1
    Thank you very much. I thought that the default would be `false` but the fact that [something is minifying my non-release build](http://stackoverflow.com/q/29761457/4807784) is a mystery to me. How do I find what is responsible for minifying my debug build? I am new to Android Studio and Gradle and at this point I am groping in the dark. Any tips on that? +1 for now, will accept once I have better insight into what's going on. – ususer Apr 24 '15 at 12:39
  • I just posted an update, in case this could provide additional insight. I am still groping in the dark. Thanks. – ususer Apr 24 '15 at 14:04
  • Yup. A bug in Android's Gradle plugin: https://code.google.com/p/android/issues/detail?id=52962 – ususer Apr 24 '15 at 21:35