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

时间:2016-05-17 15:17:37

标签: android android-jack-and-jill

我试图用新的Jack Compiler编译我的Android应用程序。使用默认的proguard安卓规则进行缩小失败。

我得到的信息是

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

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

什么有效

如果我只是从proguardFiles列表中排除 proguard-android.txt ,那么课程的构建将会起作用但我不知道的是我是否假设这样做;这会遗漏一些可能会破坏我的应用程序的重要内容吗?或者所有这些设置都是内置在杰克的新缩放器中的?

修改

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

1 个答案:

答案 0 :(得分: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'
}