Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

android - How to perform minification and obfuscation with the JACK compiler?

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:

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

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:

Further References:

Update:

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...