gradle-retrolambda icon indicating copy to clipboard operation
gradle-retrolambda copied to clipboard

Error in ./gradlew build in Android Studio 2.2.2

Open dev-chulbuji opened this issue 8 years ago • 10 comments
trafficstars

i am using gradle version 2.14.1, plugin 2.2.2, retrolambda v3.4 for new android project (added compileOptions)

but ./gradlew build cannot complete in my project.

here is my error screenshot

image

dev-chulbuji avatar Dec 06 '16 13:12 dev-chulbuji

I've just seen the same error.

project level gradle file

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
        classpath 'me.tatarka:gradle-retrolambda:3.6.0'

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

//plugins {
//    id "me.tatarka.retrolambda" version "3.5.0"
//}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

module level gradle file

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

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"
    compileOptions {
        sourceCompatibility org.gradle.api.JavaVersion.VERSION_1_8
        targetCompatibility org.gradle.api.JavaVersion.VERSION_1_8
    }
    defaultConfig {
        applicationId "mmm.expenselogger"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        //testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
        jackOptions {
            enabled true
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    //androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    //    exclude group: 'com.android.support', module: 'support-annotations'
    //})

    // android imports
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.android.support:design:24.0.0'
    compile 'com.android.support:support-v4:24.0.0'
    compile 'com.android.support:recyclerview-v7:24.0.0'

    // external libraries
    compile 'joda-time:joda-time:2.9.7'
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.github.clans:fab:1.6.4'
    compile 'commons-lang:commons-lang:2.6'
    compile 'com.google.guava:guava:21.0'
    compile 'net.sourceforge.streamsupport:streamsupport:1.5.3'
    compile 'net.sourceforge.streamsupport:streamsupport-cfuture:1.5.3'
    compile 'net.sourceforge.streamsupport:streamsupport-atomic:1.5.3'
    compile 'net.sourceforge.streamsupport:streamsupport-flow:1.5.3'
    compile 'net.sourceforge.streamsupport:streamsupport-literal:1.5.3'

    //testCompile 'junit:junit:4.12'
}

retrolambda {
    javaVersion org.gradle.api.JavaVersion.VERSION_1_7
}

monemihir avatar Mar 03 '17 04:03 monemihir

The plugin isn't compatible with jack.

evant avatar Mar 03 '17 04:03 evant

The moment I set compileOptions to Java8, Android Studio tells me I need to enable jack.

Does that mean I can't use this plugin?

monemihir avatar Mar 03 '17 04:03 monemihir

They cover the same feature set, use one or the other.

evant avatar Mar 03 '17 04:03 evant

sorry i don't quite understand...can you please tell me what updates I should do to my gradle file?

monemihir avatar Mar 03 '17 04:03 monemihir

Do you want to use jack, or retrolambda? Both support backporting lambdas. Jack is "officially supported" but has some known issues currently like slower builds, not compatible with instant run etc.

To use retrolambda, remove:

jackOptions {
  enabled true
}

Ignore any warning from Android Studio, it will work fine.

To use jack, remove:

apply plugin: 'me.tatarka.retrolambda'
...
retrolambda {
    javaVersion org.gradle.api.JavaVersion.VERSION_1_7
}

evant avatar Mar 03 '17 04:03 evant

Do I still need to set the compileOptions option set?

If I disable jack the project builds properly, but I get an error

Error:Lambda expressions not supported at this language level

If I set the compileOptions then the build asks to enable jack and enabling it and disabling retrolambda the build still breaks with error

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

monemihir avatar Mar 03 '17 05:03 monemihir

Yes, you still need compileOptions, it's described in the README.

retrolambda (and jack) only backport the lambda language feature. They do not backport any java 8 apis so java.util.function.Supplier will not be avaialble before Nouget. jack is doing a little better here failing and compile time, retrolambda will fail at runtime.

evant avatar Mar 03 '17 13:03 evant

ok cool thanks a lot, i've got it working now

monemihir avatar Mar 04 '17 11:03 monemihir

I removed this, it can build, but not run..... jackOptions { enabled true }

tianxu0836 avatar Dec 20 '17 01:12 tianxu0836