4

我正在尝试使用新的 Jack Compiler 编译我的 Android 应用程序。使用默认的 proguard 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$000(JackTask.java:73)
    at com.android.build.gradle.tasks.JackTask$1.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

这是一个标准的安卓 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'
}

什么有效

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

编辑

我尝试排除proguard-android.txt并进行了测试。我的应用程序崩溃了,因为 Guava 的某些部分被缩小/混淆了。

4

1 回答 1

0

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

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'
}
于 2017-03-14T19:12:54.670 回答