如何使用 JACK 编译器执行缩小和混淆? [英] How to perform minification and obfuscation with the JACK compiler?

查看:20
本文介绍了如何使用 JACK 编译器执行缩小和混淆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google 已经发布了适用于 Android 的新 JACK 编译器的测试版本使用 Android Studio 2.1 的开发人员.

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

我的问题是,我们如何使用 JACK 对 APK 启用混淆?下面的文章说 JACK 本地执行混淆并消除了对 Proguard 的需要:

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:

而以下文章说 JACK 使用 Proguard 配置文件(即 .pro 文件)来执行混淆:

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

它也说

在此过程中,Jack 还会处理任何请求的代码压缩(缩小和/或混淆).

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

这到底是什么意思?我们是否必须使用 minifyEnabled 选项并定义一个包含 Proguard 选项的 .pro 文件?

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

总结:

  • 我们究竟如何使用 JACK 启用混淆?我们可以吗绕过 Proguard 的使用,或者 Proguard 在混淆过程,即使我们用 JACK 编译?

  • 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?

JACK 目前是否支持混淆,是否可用在稳定(即非测试版/金丝雀)版本的 Android Studio 中?

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

注意:

我已经参考了以下帖子:

I have already referred the following posts:

错误:Jack 需要支持 Java 8 语言功能.

进一步参考:

杰克的阴暗面和吉尔.

Java 8 语言功能.

更新:

答案 来自 Matt Insko 很有帮助,但我想要更详细、更准确、更规范的答案.

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

推荐答案

J.A.C.K.最新发布的 Gradle 插件 (v2.1.0) 似乎不支持混淆.

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

如果您在使用最新的 v2.1.0 插件时启用 JACK,它会告诉您 Jack 需要 Build Tools 24.0.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.

使用 android gradle v2.2.0-alpha1、Build Tools-v24rc4、Platform Tools-v24rc3 和 Sdk Tools-v25.1.7rc1,我能够让 JACK 执行混淆.

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.

defaultConfig 中启用时,它抱怨 使用 Jack 时不支持缩小用于测试的变体.,因为 minifyEnabled truedebug 构建.

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
        }
    }

使用proguardFiles getDefaultProguardFile('proguard-android.txt') 时出现问题.它出错了:com.android.jack.api.v01.ConfigurationException: Error while parsing ..., .所以,我只是删除了它抱怨的行,然后手动指定了我修改过的配置文件.

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 编译器执行缩小和混淆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆