1

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.

Nicholas Pesa
  • 2,156
  • 2
  • 24
  • 45
  • 1
    Have you tried invalidating the cache and restarting Android Studio? – Jaythaking Sep 12 '16 at 21:38
  • @cricket_007 I would like to get these issues resolved before relying on backport libraries, because it seems that google is pushing towards Java8 for all future releases. – Nicholas Pesa Sep 12 '16 at 21:52
  • @Jaythaking I tried invalidating cache and restarting but still the same issues, I have added one additional error that I missed before as well. Thanks for the quick answers, but still same log errors. – Nicholas Pesa Sep 12 '16 at 21:53
  • Did you just switch to Java8 AND also upgrade your targetSdkVersion to 24? Because i was having a similar issue that was caused because I didnt download the API 24 Nougat SDK through the SDK Manager... – Jaythaking Sep 12 '16 at 21:55
  • @Jaythaking yeah I have switched everytthing to nougat, my build.gradle above shows that the target is 24, and the build tools are using 24.0.2 now as well. – Nicholas Pesa Sep 12 '16 at 22:07
  • And you downloaded the required SDK through the SDK manager of Android Studio? – Jaythaking Sep 12 '16 at 22:18
  • @Jaythaking Yes the correct SDK is downloaded and being used – Nicholas Pesa Sep 12 '16 at 22:23

3 Answers3

1

We're looking into this, I think it's due to different behavior of the Android Gradle plugin for Jack and javac. As a workaround, you can try this in jackOptions

additionalParameters = [ "jack.import.type.policy" : "keep-first" ]

But be aware that with that option, Jack will keep the first definition of the class it encounters.

You can track our progress here: https://code.google.com/p/android/issues/detail?id=222273

Lukas Bergstrom
  • 757
  • 4
  • 3
  • Berstrom Thanks for the response, I will track the progress. Does this additionalOptions line have to go in jackOptions{}? I have placed it there and am now getting a gradle build error: Error:(16, 0) Could not set unknown property 'additionalParameters' for JackOptions_Decorated{isEnabled=true, isJackInProcess=null} of type com.android.build.gradle.internal.dsl.JackOptions. Open File As well should i be commenting on the google code issue tracker? – Nicholas Pesa Sep 13 '16 at 20:57
  • 1
    I have done some more research on Jack and see that the correct format for the additional parameters tag is like so: additionalParameters("jack.import.type.policy" : "keep-first"). This gives me gradle build errors saying 'Could not find method additionalParameters() for arguments[{arguments}]..... and I have tried other arguments shown when viewing the help properties of the jack.jar in the CL but none of the arguments seem to take. It is recognizing this method now where as before it was seeing an unknown property. – Nicholas Pesa Sep 13 '16 at 22:16
  • I see that you have solved your problem, but in case we have a bug with Jack parameters, what version of the Android Gradle plugin are you using? – Lukas Bergstrom Sep 14 '16 at 19:17
  • Can't reproduce your problem using additionalParameters with Build Tools 24.0.2 and plugin com.android.tools.build:gradle:2.2.0 – Lukas Bergstrom Sep 14 '16 at 19:23
  • I was using Android Gradle plugin 2.1.3 because i saw 2.2.0 was only in RC stage, but once I switched to 2.2.0 the additionalParameters option takes with arguments. I really appreciate all the help here as well! – Nicholas Pesa Sep 14 '16 at 20:51
0

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.

Nicholas Pesa
  • 2,156
  • 2
  • 24
  • 45
0

I met the same problem,Then I found a same package in these two jar,But them are not a same version. So modify to them have a same version.