使用 Jack APIs v01 编译失败 - ConfigurationException:解析 proguard-android.txt 时出错

Compilation with Jack APIs v01 Fails - ConfigurationException: Error while parsing proguard-android.txt

我正在尝试使用新的 Jack 编译器编译我的 Android 应用程序。使用默认混淆器 android 规则的缩小失败。

我收到的消息是

Error:Execution failed for task ':app:compileDebugJavaWithJack'.
> java.io.IOException: com.android.jack.api.v01.ConfigurationException: Error while parsing 'C:\Users\Jonathan\AppData\Local\Android\sdk\tools\proguard\proguard-android.txt':43

Gradle 控制台输出

:app:compileDebugJavaWithJack
Jack APIs v01 configuration failed
com.android.jack.api.v01.ConfigurationException: Error while parsing 'C:\Users\Jonathan\AppData\Local\Android\sdk\tools\proguard\proguard-android.txt':43
    at com.android.jack.api.v01.impl.Api01ConfigImpl.getTask(Api01ConfigImpl.java:77)
    at com.android.builder.core.AndroidBuilder.convertByteCodeUsingJackApis(AndroidBuilder.java:1914)
    at com.android.build.gradle.tasks.JackTask.doMinification(JackTask.java:148)
    at com.android.build.gradle.tasks.JackTask.access[=12=]0(JackTask.java:73)
    at com.android.build.gradle.tasks.JackTask.run(JackTask.java:112)
    at com.android.builder.tasks.Job.runTask(Job.java:51)
    at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
    at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:223)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.android.jack.IllegalOptionsException: Error while parsing 'C:\Users\Jonathan\AppData\Local\Android\sdk\tools\proguard\proguard-android.txt':43
    at com.android.jack.Jack.check(Jack.java:426)
    at com.android.jack.api.v01.impl.Api01ConfigImpl.getTask(Api01ConfigImpl.java:71)
    ... 8 more
Caused by: com.android.jack.antlr.runtime.RecognitionException
    at com.android.jack.shrob.proguard.ProguardParser.recoverFromMismatchedToken(ProguardParser.java:138)
    at com.android.jack.antlr.runtime.BaseRecognizer.match(BaseRecognizer.java:115)
    at com.android.jack.shrob.proguard.ProguardParser.arguments(ProguardParser.java:2967)
    at com.android.jack.shrob.proguard.ProguardParser.member(ProguardParser.java:2349)
    at com.android.jack.shrob.proguard.ProguardParser.members(ProguardParser.java:2174)
    at com.android.jack.shrob.proguard.ProguardParser.classSpecification(ProguardParser.java:1863)
    at com.android.jack.shrob.proguard.ProguardParser.prog(ProguardParser.java:388)
    at com.android.jack.shrob.proguard.GrammarActions.parse(GrammarActions.java:341)
    at com.android.jack.Jack.check(Jack.java:423)
    ... 9 more

proguard-android.txt

这是一个标准的 android SDK 文件。我没有修改它。它不喜欢的行在下面的摘录中。

# Keep setters in Views so that animations can still work.
# Setters for listeners can still be removed.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
    void set*(%);
    void set*(%, %);
    void set*(%, %, %, %);
    void set*(%[]); //LINE 43, THROWS ERROR
    void set*(**[]);
    void set*(!**Listener);

    % get*();
    %[] get*();
    **[] get*();
    !**Listener get*();
}

Gradle.config

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '24rc2'

    defaultConfig {
        applicationId "com.company.myapplication"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        jackOptions {
            enabled true
        }
    }
    testBuildType "no_proguard"
    buildTypes {
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable true
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        no_proguard {
            minifyEnabled false
            debuggable true
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.android.support:design:23.4.0'
}

什么有效

如果我只是将 proguard-android.txt 从 proguardFiles 列表中排除,构建当然会工作,但我不知道我是否 应该这样做;这是否遗漏了可能破坏我应用程序一部分的重要内容?还是所有这些设置都内置在 Jack 的新 minifier 中?

编辑

我尝试排除 proguard-android.txt 并进行了测试。我的应用程序崩溃了,因为 Guava 的某些部分已 shrunk/obfuscated 离开。

现在可以用了,我已经更新了几个库和编译工具

Gradle.config

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.test.myapplication"
        minSdkVersion 9
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        jackOptions {
            enabled true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    testBuildType "no_proguard"
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        no_proguard {
            minifyEnabled false
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:design:25.2.0'
    compile 'com.android.support:support-vector-drawable:25.2.0'
    testCompile 'junit:junit:4.12'
}