Adam Dye Adam Dye - 4 months ago 120
Android Question

Lambda causes complier exception in Android Library Module

When I use a lambda expression in an Android Library Module, I receive a compiler exception$CompletionFailure: class file for java.lang.invoke.MethodType not found

Lambda expressions are compiling without error when used in the Android application module.

A sample project to demonstrate the problem can be found here:

The interesting classes in the example are and Each class contains the identical expressions.


Android Studio 2.2 preview 1
min/target SDK version = android-N
build tools version = 24.0.0.rc4
jack compiler enabled
source/target compatibility = 1.8
Gradle version = 2.10
Android Plugin Version = 2.2.0-alpha1
JDK = java 8

I am not interested in using retro-lambda. I'd like to get this working through proper configuration. I assume I'm missing a step somewhere.


Just to circle back, and add what I've learned.

I was able to get past the MethodType not found error by adding my JAVA HOME's runtime jar to gradle's bootclasspath in the project's build.gradle file.

allprojects {    
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xbootclasspath/a:" +"java.home") + "/lib/rt.jar"

However, the app would not deploy to a device or emulator because the app:transformClassesWithPreJackPackagedLibrariesForDebug gradle task fails. It requires that all interfaces that are used as a lamba are on the classpath. The bootclasspath fix did not set the classpath for the Jack compiler and libraries do not use the Jack compiler yet.

I opened a bug report on this issue:

They commented that this will be addressed in the near future.