Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use new Android 2.0 Shrinker and set useProguard false?

I upgraded to Android Studio 2.0 Beta 5. I'm using gradle tools 2.0.0-beta5. On the Android dev blogspot site, there is a video explaining how to use the new Shrinker for debug builds (at 3:14)

https://www.youtube.com/watch?list=PLWz5rJ2EKKc_w6fodMGrA1_tsI3pqPbqa&v=xxx3Fn7EowU

I'm trying to build my project with the debug buildType as explained in the video:

    debug {
        minifyEnabled true
        useProguard false
    }

I'm getting a bunch of warnings and then this this error when building:

Error:Execution failed for task 'app:transformClassesWithNewClassShrinkerForMyAppNameGoesHereDebug'.
Warnings found during shrinking, please use -dontwarn or -ignorewarnings to suppress them.

With Proguard, I would add the appropriate -dontwarn necessary in the proguard project file. Is there a Shrinker project file somewhere that I can add -dontwarn statements?

like image 374
Lou Morda Avatar asked Feb 26 '16 22:02

Lou Morda


People also ask

What are shrinking controls in Android?

Code shrinking (or tree-shaking): detects and safely removes unused classes, fields, methods, and attributes from your app and its library dependencies (making it a valuable tool for working around the 64k reference limit).

What tool does Android use to shrink code?

January 11, 2022. R8 is a tool that is used to shrink, secure, and optimize Android applications. It uses proguard rules to change the behavior of application.

What is minify enabled?

minify is an Android tool that will decrease the size of your application when you go to build it. It's extremely useful as it means smaller apk files! It detects any code or libraries that aren't being used and ignores them from your final apk.

How do I enable R8 on my Android?

To enable R8 shrinking in your application, set the minifyEnabled to true in your app's main build. gradle file.


1 Answers

I found some documentation on this. Turns out it uses the same configuration files as Proguard. Here is the relevant part from the doc:

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.

Also, here is a sample configuration for reference:

buildTypes {
    debug {
        minifyEnabled true
        useProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
like image 119
George Mulligan Avatar answered Sep 27 '22 15:09

George Mulligan