javaandroidandroid-studioandroid-buildandroid-jack-and-jill

Android Studio build errors with jack enabled


So i recently switched my Android Studio default JDK to Java 8, so I could use Lambda expressions. I had to enable Jack to let the gradle build, but now when I try to rebuild my applicaiton, I am getting about 3 different errors that seem to be coming from Jack. I can't seem to find the root of any of these problems, and would like to stay building with J8. Any insight or help for this is much appreciated. Here are the errors I am getting during build:

1)

Error:Library reading phase: Type javax.inject.Named from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar' has already been imported from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar', type 'javax.inject.Named' (see property 'jack.import.type.policy' for type collision policy)

2)

Error:com.android.jack.JackAbortException: Library reading phase: Type javax.inject.Named from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar' has already been imported from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar', type 'javax.inject.Named' (see property 'jack.import.type.policy' for type collision policy)

3)

Error:com.android.jack.backend.jayce.TypeImportConflictException: Type javax.inject.Named from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar' has already been imported from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar', type 'javax.inject.Named' (see property 'jack.import.type.policy' for type collision policy)

4)

:app:compileDebugJavaWithJack FAILED Error:Execution failed for task ':app:compileDebugJavaWithJack'. java.io.IOException: com.android.jack.api.v01.CompilationException: Library reading phase: Type javax.inject.Named from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar' has already been imported from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar', type 'javax.inject.Named' (see property 'jack.import.type.policy' for type collision policy)

Here is the app level build.gradle:

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "com.nicholas.baseintegrations"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"

        jackOptions {
            enabled true
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    useLibrary  'org.apache.http.legacy'

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.google.android.gms:play-services-gcm:9.4.0'
    compile project(path: ':backend', configuration: 'android-endpoints')
    compile "com.getbase:basecrm-java:1.4.3"
    compile 'com.android.support:recyclerview-v7:24.2.0'
    compile 'com.android.support:palette-v7:24.2.0'
    compile 'com.android.support:cardview-v7:24.2.0'
    compile 'com.android.support:design:24.2.0'
    compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'
    compile group: 'org.glassfish.jersey.media', name: 'project', version: '2.23.2', ext: 'pom'
}

All help is very appreciated, as I know this is a new things, but cannot seem to find questions regarding the Jack/J8 build process. Thanks in advance.


Solution

  • I ended up solving this build issue. One of my dependencies was adding a second javax.inject library which was throwing these build errors saying that the javax.inject jar had already been imported from a previous one.

    So I had javax.inject-1 and javax.inject-2.4.0-b10. I ended up excluding the javax.inject module from one of my dependencies and it cleared up issues with the build and is working jsut fine now.

    Here is the dependencies section of my app build.gradle:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile project(path: ':backend', configuration: 'android-endpoints')
        compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'
        compile (group: 'org.glassfish.jersey.media', name: 'project', version: '2.23.2', ext: 'pom')
        compile 'com.android.support:appcompat-v7:24.2.1'
        compile 'com.google.android.gms:play-services-gcm:9.4.0'
        compile ('com.getbase:basecrm-java:1.4.3') {
            exclude (group: 'javax.inject', module: 'javax.inject')
        }
        compile 'com.android.support:recyclerview-v7:24.2.1'
        compile 'com.android.support:palette-v7:24.2.1'
        compile 'com.android.support:cardview-v7:24.2.1'
        compile 'com.android.support:design:24.2.1'
    }
    

    And you can see the group exclusion in the basecrm dependency. So if anyone else has this issue just watch out for duplicate External Libraries coming from some dependency import.