gradle-retrolambda
gradle-retrolambda copied to clipboard
Problem setting up retrolambda in build.gradle files
Hi,I have a problem. I'm using retrolambda on Android Studio because lambda expression are not supported on it and I need them for my app. Here's my build.gradle file (about the project)
'buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
}
}
allprojects {
repositories {
jcenter()
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.4.0'
}
}
// Required because retrolambda is on maven central
repositories {
mavenCentral()
}
apply plugin: 'com.android.application' //or apply plugin: 'java'
apply plugin: 'me.tatarka.retrolambda'`
When I try to synchronize the project with gradle files it shows this error: "Gradle sync failed: Cause: buildToolsVersion is not specified."
I'll post also the build.gradle file for the specific app module,maybe the problem is that I use another external library:
`apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.android.sip"
minSdkVersion 21
targetSdkVersion 21
jackOptions {
enabled true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile files('src/main/java/libs/spark-core-2.3.jar')
}`
Thanks everyone.
Yeah, I had the same problem - if I added the stuff to the beginning of my app/build.gradle, though, rather than my root build.gradle, gradle completes successfully. (If that's the file that's SUPPOSED to be modified, it would be nice if the docs said so. Hint hint, developers.) However, though gradle finishes the "Rebuild project", if I actually try to debug it, Android Studio says:
Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.

Same problem here! I don't know what to do,I just need to use a library that implements lambda expression,but I can't compile.I tried to add this part of code
android { ... defaultConfig { ... jackOptions { enabled true } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }
as said here but nothing...
@BertPe you shouldn't use jack if you are using this library.
Why not to use retrolamda in the android library too?
@BertPe I had the same error, too. One of my libraries had been compiled to java 8. (It was my own library. :P ) Is it an open source library? You might be able to compile it to java 7, possibly using retrolambda as @iNoles suggested.
Oh, if you have trouble figuring out which library is causing the trouble, I turned SO answers into two windows batch files which together show you the java version numbers of the classes in a given library:
get_versions.bat:
for /f "usebackq delims=" %%x in (`get_classes.bat %1`) do javap -verbose -classpath %1 %%x | grep "major"
get_classes.bat:
@jar -tf %1 | grep "class$" | sed s/\.class$//
You'll probably need some windowsified unix tools. These might work: http://unxutils.sourceforge.net/
Basically, copy the batch files into the directory with the jars you want to inspect, and run get_versions.bat <JARFILE>, and look for "52".
It may be worth noting that I was unable to get ordinary retrolambda working with my dependee eclipse project library thing, and thankfully I was able to just use plain java 7 for it.