Gradle + Retrolambda:致命错误:无法在类路径或bootclasspath中找到包java.lang

时间:2014-08-15 23:23:14

标签: java android intellij-idea gradle java-8

我正在尝试将gradle-retrolambda集成到我的Android项目中(在this指南之后),但是当我运行gradle build时出现以下错误

:app:compileDebugJava
Fatal Error: Unable to find package java.lang in classpath or bootclasspath

堆栈跟踪:

org.gradle.api.tasks.TaskExecutionException:任务':app:compileDebugJava'的执行失败。         at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)         在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)         在org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)         在org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)         在org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)         在org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)         在org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)         在org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53) .... 引起:org.gradle.api.internal.tasks.compile.CompilationFailedException:编译失败;请参阅编译器错误输出以获取详细信         在org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:47)         在org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:38)         在org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJav) ...

我觉得很奇怪,它使用了jdk6.Jdk6JavaCompiler虽然我配置了Java7兼容性,但请参阅下面的gradle构建文件。

Gradle版本信息:

------------------------------------------------------------
Gradle 1.12
------------------------------------------------------------

Build time:   2014-04-29 09:24:31 UTC 
Build number: none 
Revision:     a831fa866d46cbee94e61a09af15f9dd95987421

Groovy:       1.8.6
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
Ivy:          2.2.0
JVM:          1.8.0_11 (Oracle Corporation 25.11-b03)
OS:           Linux 3.13.0-32-generic amd64

Java环境路径:

JAVA_HOME=/usr/lib/jvm/java-8-oracle
JAVA8_HOME=/usr/lib/jvm/java-8-oracle
JAVA7_HOME=/usr/lib/jvm/java-7-oracle

Gradle构建文件:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
        classpath 'me.tatarka:gradle-retrolambda:2.2.1'
   }

}

repositories {
    mavenCentral()
    flatDir {
        dirs 'prebuilt-libs'
    } 
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion "Google Inc.:Glass Development Kit Preview:19"
    buildToolsVersion "20.0.0"

   defaultConfig {
        minSdkVersion 19
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
    }

     compileOptions {
         sourceCompatibility JavaVersion.VERSION_1_8
         targetCompatibility JavaVersion.VERSION_1_8
    }

    packagingOptions {
         exclude 'LICENSE.txt'
         exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
} 

 dependencies {
     // gcm (old client library)
     compile fileTree(dir: 'libs', include: ['*.jar'])

     // auto factory (https://github.com/google/auto/tree/master/factory)
     compile 'com.google.auto.factory:auto-factory:0.1-beta1'   

     // auto value (https://github.com/google/auto/tree/master/value)
     compile 'com.google.auto.value:auto-value:1.0-rc1'

     // dagger
     compile 'com.squareup.dagger:dagger:1.2.0'
     provided 'com.squareup.dagger:dagger-compiler:1.2.0'   

     // butterknife for view injection
     compile 'com.jakewharton:butterknife:5.1.1'

     // javax annotations (needed for auto generated files)
     compile 'javax.annotation:jsr250-api:1.0'

     // google guava
     compile 'com.google.guava:guava:17.0'

     // support library
     compile 'com.android.support:support-v4:20+'

    // google zxing barcode reader
    compile 'com.google.zxing:core:2.3.0'

     // progress bar - https://github.com/w9jds/GDK-ProgressBar
    compile 'com.w9jds.gdk.progresswidget:library:1.0@aar'

    // espresso - https://github.com/JakeWharton/double-espresso
    androidTestCompile ('com.jakewharton.espresso:espresso:1.1-r3') {
        exclude group: 'com.squareup.dagger'
        exclude group: 'com.android.support'
    } 
}

apply plugin: 'retrolambda'

retrolambda {
    jdk System.getenv("JAVA8_HOME")
    oldJdk System.getenv("JAVA7_HOME")
    javaVersion JavaVersion.VERSION_1_7 
}

为了验证我的java8安装,我在intellij中创建了一个没有retrolambda的gradle项目,这只是工作正常。

任何想法,这里可能出现什么问题以及如何解决它?

1 个答案:

答案 0 :(得分:0)

如果您已经设置,则不再需要Retrolambda

compileOptions {
     sourceCompatibility JavaVersion.VERSION_1_8
     targetCompatibility JavaVersion.VERSION_1_8
}