Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Error: Unable to find package java.lang in classpath or bootclasspath #36

Closed
fschoellhammer opened this issue Aug 15, 2014 · 18 comments

Comments

@fschoellhammer
Copy link

Hi, I am trying to integrate gradle-retrolambda in my Android project, but I am getting the following error when I run my gradle build

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

Stacktrace:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugJava'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
....
Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.
at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:47)
at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:38)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJav

I thought it was strange, that it uses the jdk6.Jdk6JavaCompiler although I configured for Java7 compatibility, see below.

Gradle version info:
------------------------------------------------------------
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 environment paths:
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 build file:

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 
}

Just to verify my java8 installation, I created a gradle project in intellij without retrolambda, and that works fine.

Do you have any idea, what might go wrong here and how to fix it?

@evant
Copy link
Owner

evant commented Aug 17, 2014

Do you have the correct android sdk version downloaded? Try checking app/build/retrolamba to see if the patched android.jar is present. If it is, run gradle compileDebugJava --info and look at the output where it tries to compile your classes, it should contain -bootclasspath <patched-android-jar>. Make sure that it points to the correct place.

@mkuprionis
Copy link

Had the same problem. The compiler options looks like this:

Compiler arguments: \
-d /Users/mindaugas/<project path>/app/build/retrolambda/debug \
-g -encoding UTF-8 \
-bootclasspath /Users/mindaugas/Applications/android-sdk/platforms/android-20/android.jar \
-bootclasspath /Users/mindaugas/<project path>/app/build/retrolambda/android-L/android.jar
-classpath <...>

Problem seems to be that the patched android.jar contains classes from java.lang.invoke package only. Temporarily solved this by manually patching the stock android.jar.

@evant
Copy link
Owner

evant commented Sep 20, 2014

@mkuprionis It sounds like it's not finding the android.jar to patch. Would you mind testing with the SNAPSHOT version of the plugin? (Instructions in the README of the develop branch). I've added a check so it will fail if it's not found.

Could you also check your ANDROID_HOME and local.properties file to see if everything looks correct?

@mkuprionis
Copy link

Ok, seems this is related to Android L. To compile against it I need to set compileSdkVersion "android-L". Android plugin correctly resolves this to path <sdk>/platforms/android-20, but gradle-retrolambda tries to find android.jar in path <sdk>/platforms/android-L which doesn't exist.

Possible to solve this by creating a symlink: cd <sdk>/platforms; ln -s android-20 android-L.

@evant
Copy link
Owner

evant commented Sep 20, 2014

I have an android-L directory on my computer. Are you sure that your android sdk is up to date? Seems strange that it would point to android-20 because wouldn't that prevent you from using any of the new api's?

@mkuprionis
Copy link

Well this is strange. I'm using SDK managed by Android Studio. It has Android L installed and everything is up to date. But there's only platforms/android-20 directory, no platforms/android-L.

However there's also a standalone SDK in another location which I haven't used for a while. There I found platforms/android-L. Weird

@evant
Copy link
Owner

evant commented Sep 20, 2014

Yeah, I don't even know how that even would work. I'll leave this issue open so that others can find it if they run into that craziness.

@evant
Copy link
Owner

evant commented Sep 21, 2014

I updated the README to include the work around, So I don't need to keep the issue open.

@IlyaEremin
Copy link

@evant I have same problem. I use 2.4.1, AS 1.1.0 and sdk 21.
I have no android.jar into app/build/retrolamba folder and my question is how to generate it?

@evant
Copy link
Owner

evant commented Feb 19, 2015

Try running gradle clean patchAndroidJar --info and look at the output for that task. It should list where it's copying from and to. Make sure those paths look correct.

@paulrenn
Copy link

paulrenn commented Mar 2, 2015

Hi,
I'm also experiencing "Fatal Error: Unable to find package java.lang in classpath or bootclasspath".
In may case I am compiling against 'Google Inc.:Google APIs:21' using Gradle. I made a symbolic link in my sdk/platforms directory from 'Google Inc.:Google APIs:21' to android-21 but this did not work.
The app/build/retrolambda/Google\ Inc.:Google\ APIs:21/ folder contains android.jar but app/build/retrolambda/classes/java only contains lang/invoke, I suppose this is not normal.
Any suggestions?
Cheers, Paul

@vashisthg
Copy link

@paulrenn any solutions?

@feugatos
Copy link

I'm also experiencing the same problem as @paulrenn . Creating a simlink from Google Inc.:Google APIs:21 to android-21 doesn't fix the problem.

@paulrenn
Copy link

I was not able to solve this directly. The only workaround I found, which was not very satisfactory, was to make a library where all the RX calls could be done, which I was able to compile without the Google APIs. Then I have the main app which requires Google APIs but is unable to use RX.

@evant
Copy link
Owner

evant commented Apr 3, 2015

Try with 3.0.0, it should fix this

@leiweibo
Copy link

leiweibo commented Jul 1, 2015

Hi @evant , I am using the latest gradle-retrolambda(3.2.0) but still get the same issue, I can not see the android.jar in build/retrolambda folder neither.

There are JDK 1.7 and 1.8 in my pc, and I set 1.8 as my JAVA_HOME and the JAVA8_HOME in my system variable as well.

Any further suggestion?

@leiweibo
Copy link

leiweibo commented Jul 1, 2015

Hello @evant , finally I change jdk value from System.getenv to '/Library/xxx/Home<>', it works. Could you please explain this? I will also keep an eye on this. Anyway, really appreciate for the great project.

retrolambda {
    jdk '/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home'//System.getenv("JAVA_8")
    oldJdk System.getenv("JAVA7_HOME")
    javaVersion JavaVersion.VERSION_1_7
}

@ExPixel
Copy link

ExPixel commented Aug 13, 2015

Same issue, same fix as @leiweibo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants