36

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.

Yash Sampat
  • 30,051
  • 12
  • 94
  • 120
  • This [post](http://www.androidpolice.com/2014/11/30/jack-and-jill-are-googles-new-compilers-for-android-app-developers/) could be helpful. If you see this [link](http://tools.android.com/tech-docs/jackandjill) there is an option to pass proguard files like `--config-proguard` – Madhukar Hebbar May 19 '16 at 06:41
  • So using command line is the only option here? And how exactly do we build using JACK from the command line? – Yash Sampat May 19 '16 at 07:33
  • Ya, I tried with the CLI. It's working fine. This information is mentioned [here](https://software.intel.com/en-us/android/articles/an-introduction-to-jack-and-jill-on-x86) and [here](https://gist.github.com/stefanhoth/593451dfb4576ec9a21c) – Madhukar Hebbar May 19 '16 at 09:05
  • 1
    Thanks, but I already saw that first link (its even referenced in my answer) ... thanks anyway :) – Yash Sampat May 19 '16 at 10:15
  • 1
    A nice informative question. – Madhukar Hebbar May 19 '16 at 14:54
  • This should work now in 3.0, where by default we use the custom code shrinker for Instant Run builds. The custom shrinker is compatible with resource shrinking. for more update may you can check https://issuetracker.google.com/issues/37092766 – Prags Dec 16 '17 at 05:42

2 Answers2

9

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.

Matt Insko
  • 261
  • 1
  • 4
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.

  • 3
    Thanks, but you don't explain how exactly do we go about this. I too have read (and referenced) that article, and its pretty cryptic and vague as to how exactly obfuscation is done. If you can try it out, and provide some more details (if it works), I'd be grateful .... thanks :) – Yash Sampat May 25 '16 at 04:06