Android Jack: Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.util.function.Consumer

我们两清 提交于 2019-12-18 12:53:06

问题


Getting this on android studio 2.2.

Does anyone have a workaround?

My app build file is:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "acme.cb2"
        minSdkVersion 18
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        jackOptions {
            enabled true
        }

    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:support-v4:24.1.1'
}

edit: modifid the main build file to include answer from https://stackoverflow.com/users/5753091/mohammadreza-khalifeh - but this did not help

import java.text.SimpleDateFormat

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'
        classpath 'org.hidetake:gradle-ssh-plugin:2.4.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xbootclasspath/a:" + System.properties.get("java.home") + "/lib/rt.jar"
        }
    }
}

edit: adding:

options.compilerArgs.each { println 'option: '+it}

prints out:

option: -Xbootclasspath/a:C:\Program Files\Java\jdk1.8.0_92\jre/lib/rt.jar

It looks like the space in the path might cause a problem?

edit: trying:

options.compilerArgs << "\""+"-Xbootclasspath/a:" + System.properties.get("java.home") + "/lib/rt.jar"+"\""

does not work either.


回答1:


I had this problem after adding Guava library to my dependencies.

Solution was to downgrade lib version from com.google.guava:guava:21.0 to com.google.guava:guava:20.0.

Also, I'm using classpath 'com.android.tools.build:gradle:2.5.0-alpha-preview-01`

EDIT: As you don't use this library please try to change:

  • in project build.gradle
    • classpath from classpath 'com.android.tools.build:gradle:2.2.0' to com.android.tools.build:gradle:2.5.0-alpha-preview-01
  • in app build.gradle

    • from compileSdkVersion 24 to 25
    • from buildToolsVersion "24.0.2"to 25.0.2
  • in gradle-wrapper.properties

    • change version to distributionUrl=https://services.gradle.org/distributions-snapshots/gradle-3.5-20170213202653+0000-all.zip



回答2:


add this in your build.gradle:

allprojects {
    repositories {
        jcenter()
    }
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xbootclasspath/a:" + System.properties.get("java.home") + "/lib/rt.jar"
        }
    }
}



回答3:


Try

classpath 'com.android.tools.build:gradle:2.3.+'

and

minSdkVersion 25



回答4:


upgrading android studio, the following seems to work (but it's really slow now):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"

    defaultConfig {
        applicationId "acme.cb2"
        minSdkVersion 22
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        jackOptions {
            enabled true
       }
    }
    dexOptions {
        //javaMaxHeapSize "4G"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:support-v4:25.2.0'
}


来源:https://stackoverflow.com/questions/39683608/android-jack-lambda-coming-from-jar-file-need-their-interfaces-on-the-classpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!