📜 ⬆️ ⬇️

Meet Jack and Jill on x86

Jack (Java Android Compiler Kit) is a compiler that converts Java source code to Android DEX files. Jack is a set of tools, among its features - repacking, compressing, obfuscating and supporting multiple DEX files.

Jack uses intermediate libraries in the .jack format. Converting existing .aar / .jar files into this format is done by Jill (Jack Intermediate Library Linker).


')
If Jack is used for building, Jill first converts the external libraries used in the project into .jack files. This prepares libraries to quickly merge with other .jack files in the next step, when Jack and the Android Gradle plugin, using previously prepared .jack files and Java source code, compile a DEX file (or files). During this process, Jack can minify the code (compress, obfuscate, or both). The output is an Android application APK file.


Build process using Jack and Jill

Jack and Jill are available in Build Tools for Android Studio since version 21.1.1. The Android Gradle plugin supports these tools starting from version 1.0.0. In order to use the Jack features, just add useJack = true to the build.gradle file.


Android SDK Manager

Using the command line


You can learn more about working with Jack and Jill using the commands below. Here we use the standard Windows command line interface, the Jack and Jill libraries, included in Android Build Tools version 23.0.2.
Some features of these tools may be available from the command line before their support is included in the Android Gradle plugin.

So, here is the command to get Jack help:

java –jar <Android SDK>/build-tools/< Build Tools version>/jack.jar ––help 

Its execution gives us the following:


Jack Help

And this is how you can get to know Jill:

 java –jar <Android SDK>/build-tools/< Build Tools version>/jill.jar ––help 



Jill Help

Some features of Jack


Before you start working with Jack, it is worth considering that it supports the Java 1.7 programming language. and does not support annotation processing.

When using Jack, it can transfer Proguard configuration files using the –config-proguard command line parameter. If we talk about repacking, then Jack is compatible with rules like “rule”, but not with rules like “zap” or “keep”. Rule files can be specified on the command line using the –– config-jarjar option.

Jack support by the Android Gradle plugin is still under development, so you should consider the following features and limitations:


 dexOptions { javaMaxHeapSize "2048M" } 

Let's try Jack in action.

Work with Jack


First we need some kind of experiment application project. For example, import the Hello JNI project from the sample directory. To do this, execute the File> New> Import Sample command in Android Studio. In the window that appears, find the project Hello JNI, and, selecting its name, click on the Next button.


Hello JNI project to import

In the next window, the application name (the Application name field) and the path to the new project (Project location) will not be changed, and, to complete the import, click on the Finish button.

If during the import a message appears stating that the system cannot find the NDK (Android NDK Location is not specified), correct this by clicking the Select NDK link and specifying the path to the NDK in the window that opens. This path will be written to the local.properties file as ndk.dir = <path_to_ndk>.

After successful import of the project, we find in the Project view mode, in the app folder, the file build.gradle and add the command to enable jack (useJack = true) in defaultConfig.with:

 android {       compileSdkVersion = 23       buildToolsVersion = "23.0.2"       defaultConfig.with {           applicationId = "com.example.hellojni"           minSdkVersion.apiLevel = 4           targetSdkVersion.apiLevel = 23           useJack = true       }   } 

Now let's test the system on the Asus Fonepad 8 tablet (CPU Intel Atom Z3530, Android 5.0).


Test application on x86 device

Results


Everyone who has been involved in application development knows that every second counts in this matter. One of the important features of Jack is a reduction in compilation time , which means an increase in labor productivity. In addition, Jack by default is used in Android M. Perhaps, only these two facts are enough to make Jack and Jill welcome guests in the home of any programmer.

Source: https://habr.com/ru/post/276881/


All Articles