How to perform minification and obfuscation with the JACK compiler?
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.
Jack and Jill minify equivalent
Nothing I have read suggests that there is any change needed with regard to minifyEnabled true
. And that Jack does support it and works with multidex.
From: http://tools.android.com/tech-docs/jackandjill#TOC-Overview
...Jack also handles any requested code minification (shrinking and/or obfuscation). The output is then assembled into an APK file as normal. Including support for multiple dex files if you have enabled that support.
Jack's Shrinking and Obfuscation does not support all of proguard's options however. There is a list here:
http://tools.android.com/tech-docs/jackandjill#TOC-Shrinking-and-Obfuscation-support
How to enable Jack (Java Android Compiler Kit) in android studio
The details on what is required to use Jack and how can be found in the documentation.
Here is the relevant part from the docs that goes in build.gradle
on how to use jackOptions
and set the compileOptions
for java 1.8.
android {
...
defaultConfig {
...
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
UPDATE
The Jack toolchain is now considered deprecated according to this post and work is being done to natively support Java 8 features as part of the Android build system in the coming weeks according to the post.
The post also mentions that there should be little to no work migrating from Jack to the new method in case you still wanted to try enabling Java 8 features with Jack.
UPDATE 2 Preview Built-in Support
You can now try out the new built-in support for Java 8 using the latest Android Studio preview 2.4 preview 6.
For more information on how to enable it or migrate from Jack or Retrolambda see the documentation.
Error:Jack is required to support java 8 language features
Error:Jack is required to support java 8 language features. Either
enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8.
The error say that you have to enable Jack.
To enable support for Java 8 in your Android project, you need to configure your build.gradle
file like that
android {
...
compileSdkVersion 23
buildToolsVersion "24rc2"
defaultConfig {
...
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Crashlytics don't compile when using Jack
Crashlytics task depends on dex
task, which will not be created, because Jack does dexing internally. This is most likely something Crashlytics team will have to deal with soon and fix.
Related Topics
Trying to Fix Networkonmainthreadexception But Gives Toast Error
Android Studio on a Hardware That Does Not Support Virtualization Technology
Save Webview Content to Android Storage and Load It
Android: Save File Permanently (Even After Clear Data/Uninstall)
Searchview in Centre and After Focus It Goes to App Bar in Android
How to Embed a Youtube Clip in a Webview on Android
In Android Applications What Is The Role of "R.Java"
Android: Velocity-Based Viewpager Scrolling
Failed to Resolve: Recyclerview-V7
Finish an Activity After a Time Period
Startactivityforresult from Activitygroup
Why Does Flag_Activity_Clear_Top Not Work
Firebase Servervalue.Timestamp in Java Data Models Objects
Eclipse Can't Find Android.Support.V4.Widget.Swiperefreshlayout
How to Implement Search in Customlistview Based on Class Item of Pojo Class in Android