How to perform minification and obfuscation with the JACK compiler?

瘦欲@ 提交于 2019-11-26 11:24:19

问题


Google has released a test version of their new JACK compiler for Android developers with Android Studio 2.1.

My question is, how do we enable obfuscation for the APK with JACK? The article below says that JACK performs obfuscation natively and eliminates the need for Proguard:

  • Compiling with Jack

Whereas the following article says that JACK makes use of Proguard configuration files (i.e. the .pro file) for performing obfuscation:

  • Experimental New Android Tool Chain - Jack and Jill.

It also says that

During this process Jack also handles any requested code minification (shrinking and/or obfuscation).

What exactly does this mean? Do we have to use the minifyEnabled option and define a .pro file containing the Proguard options?

In Summary:

  • How exactly do we go about enabling obfuscation with JACK? Can we bypass the use of Proguard, or does Proguard play a de-facto role in the obfuscation process, even if we compile with JACK?

  • Does JACK currently support obfuscation or not, and is it available in a stable (i.e. non-beta/canary) version of Android Studio?

Note:

I have already referred the following posts:

  • How to enable Jack (Java Android Compiler Kit) in android studio.

  • Error:Jack is required to support java 8 language features.

Further References:

  • An Introduction to Jack and Jill on X86.

  • The dark side of Jack and Jill.

  • Java 8 Language Features.

Update:

The answer by Matt Insko is helpful, but I would like more detail, and a more precise, canonical answer.


回答1:


J.A.C.K. obfuscation does not appear to be supported in the latest released Gradle Plugin (v2.1.0).

If you enable JACK when using the latest v2.1.0 plugin, it will tell you Jack requires Build Tools 24.0.0 or later requiring you to use the preview tools.

Using android gradle v2.2.0-alpha1, Build Tools-v24rc4, Platform Tools-v24rc3, and Sdk Tools-v25.1.7rc1 I was able to get obfuscation to be performed by JACK.

When enabled inside defaultConfig it complained Minifying the variant used for tests is not supported when using Jack., because minifyEnabled true was configured in the debug build.

So, I created a custom build type and enabled it there:

buildTypes {
    ...
    custom {
        minifyEnabled true
        proguardFiles 'proguard-android-JACK.txt-2.2.0-alpha1'
        jackOptions {
            enabled true
        }
    }

There was a problem when using proguardFiles getDefaultProguardFile('proguard-android.txt'). It errorred with: com.android.jack.api.v01.ConfigurationException: Error while parsing ..., . So, I just removed the lines it complained about and then just manually specified my modified configuration file.




回答2:


You can have a look here: https://source.android.com/source/jack.html

From the official documentation:

(Jack) Handles shrinking, obfuscation, repackaging and multidex. Using a separate package such as ProGuard is no longer necessary.

Please notice especially the section "Shrinking and Obfuscation" where it's mentioned that:

Jack has shrinking and obfuscation support and uses proguard configuration files to enable shrinking and obfuscation features.

And also the supported and ignored options are presented too.



来源:https://stackoverflow.com/questions/37314760/how-to-perform-minification-and-obfuscation-with-the-jack-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!