Search code examples
androidandroid-jack-and-jill

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


I'm trying to compile my Android app with the new Jack Compiler. Minification with the default proguard android rules fails.

The message I get is

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 Console Output

: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

This is a standard android SDK file. I've not modified it. The line it doesn't like is in the excerpt below.

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

What works

The build of course will work if i just exclude proguard-android.txt from the list of proguardFiles but what I don't know is if I'm supposed to do this; does that leave out something important that could break part of my app? Or are all those settings built into Jack's new minifier anyway?

Edit

I tried excluding proguard-android.txt and tested. My app crashed because some part of Guava had been shrunk/obfuscated away.


Solution

  • It works now, I have since updated several libraries and compile tools

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