What's the difference between “minifyEnabled”

2019-01-23 01:29发布

I see that the Android Plugin for Gradle has a minifyEnabled property as well as a useProguard property, as follows:

android {
    buildTypes {
        debug {
            minifyEnabled true
            useProguard false
        }
        release {
            minifyEnabled true
            useProguard true
        }
    }
}

What's the difference between these two properties? Or, rather, what's the meaning of each?

2条回答
forever°为你锁心
2楼-- · 2019-01-23 01:43

Quoting from tools.android.com:

Built-in shrinker

Version 2.0 of Android Plugin for Gradle ships with an experimental built-in code shrinker, which can be used instead of ProGuard. The built-in shrinker supports fast incremental runs and is meant to speed up iteration cycles. It can be enabled using the following code snippet:

android {
    buildTypes {
        debug {
            minifyEnabled true
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt')
        }
    }
}

The built-in shrinker can only remove dead code, it does not obfuscate or optimize. It can be configured using the same files as ProGuard, but will ignore all flags related to obfuscation or optimization.

Unlike ProGuard, we support using the built-in shrinker together with Instant Run: depending on the project, it may significantly decrease the initial build and install time. Any methods that become reachable after a code change will appear as newly added to the program and prevent an Instant Run hotswap.

查看更多
戒情不戒烟
3楼-- · 2019-01-23 01:45

Just enable minifyEnabled will have code both optimized and obfuscated. This is because useProguard true is default so no need to set it explicitly.

See also: Obfuscation in Android Studio

查看更多
登录 后发表回答