evant / gradle-retrolambda

A gradle plugin for getting java lambda support in java 6, 7 and android
Apache License 2.0
5.3k stars 449 forks source link

Problem compiling APK #157

Open rasmusson opened 8 years ago

rasmusson commented 8 years ago

I am trying to set up retrolambda for android but I am having some trouble. When Im trying to build a APK I get this error message. com.sun.tools.javac.code.Symbol$CompletionFailure: class file for java.lang.invoke.MethodType not found

Any Idea how to debug this further? Im running on mac Gradle wrapper version 2.9 JDK 1.8.0_40 JDK 1.7.0_05

Top level .gradle

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {

            classpath 'com.android.tools.build:gradle:1.1.0'
        }
    }

    allprojects {
        repositories {
            jcenter()
        }
    }

Project Level .gradle

    buildscript {
        repositories {
            maven { url 'https://maven.fabric.io/public' }
            mavenCentral()
        }

        dependencies {
            classpath 'io.fabric.tools:gradle:1.+'
            classpath 'me.tatarka:gradle-retrolambda:3.2.4'
        }
    }

    repositories {
        maven { url 'https://maven.fabric.io/public' }
        mavenCentral()
    }

    apply plugin: 'com.android.application'
    apply plugin: 'io.fabric'
    apply plugin: 'me.tatarka.retrolambda'

    retrolambda {
        oldJdk JAVA7_HOME
        jdk JAVA8_HOME
        javaVersion JavaVersion.VERSION_1_7
    }

    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.2"

        defaultConfig {
            applicationId "no.steras.ruter"
            minSdkVersion 16
            targetSdkVersion 21
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
evant commented 8 years ago

Check that JAVA8_HOME/JAVA7_HOME are resolving correctly.

rasmusson commented 8 years ago

I have these defined in gradle.properties JAVA8_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home" JAVA7_HOME="/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home"

Is there a good way I can check that they are resolved?

rasmusson commented 8 years ago

I added println JAVA7_HOME println JAVA8_HOME

In the build script. It prints "/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home" "/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home" This is correct

emredirican commented 8 years ago

I had a similar problem in our CI machine, which is also a mac. Like evant said, somehow environment variables weren't resolved correctly. I couldn't fix it via launchd for some reason, so I assigned the variables to CI tasks and agents, which solved my problem.

I guess you need to make sure the variables are resolved correctly where your scripts are executed.

rasmusson commented 8 years ago

As my last comment says, I am printing the variables and they correctly resolves to the location of the java bin folder on the corresponding jdk

mcwienczek commented 8 years ago

I've had similar problem. Locally everything compiled fine whereas on Build server I received the error above. Build server and localhost have had same project configuration. Having set JAVA_HOME for System-wide environment variable to C:\Program Files\Java\jdk1.8.0_66 fixed the problem

rasmusson commented 8 years ago

JAVA_HOME is set to my JDK8

mradzinski commented 8 years ago

Same error here on Windows 10 using JDK1.8.0_66

mradzinski commented 8 years ago

Weirdly enough, I ended up solving the issue by swapping the plugins order:

apply plugin: 'me.tatarka.retrolambda' // <---
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

retrolambda {
    jdk System.getenv("JAVA8_HOME")
    oldJdk System.getenv("JAVA7_HOME")
    javaVersion JavaVersion.VERSION_1_7
}
ericfri commented 8 years ago

I'm having what seems to be the same issue. If I build from within Studio it fails with the error

com.sun.tools.javac.code.Symbol$CompletionFailure: class file for java.lang.invoke.MethodType not found Error:Execution failed for task ':Autosense:compilePaidDebugJavaWithJavac'. Compilation failed; see the compiler error output for details.

But if I build from the terminal with Gradle it is successful.