1

Whenever I debug my app and put a breakpoint anywhere and open evaluate window, the lambda expressions are not working. (It works without any issues within the app itself)

Example code I have:

Arrays.asList("1One","1Two","1Three","1Four","2Five").stream()
        .filter(word -> word.charAt(0) == '1')
        .collect(Collectors.toList());

In the app it works without any issues. But in evaluate window it throws:

Compilation failed:
cannot find symbol
  symbol:   method metafactory(java.lang.invoke.MethodHandles.Lookup,java.lang.String,java.lang.invoke.MethodType,java.lang.invoke.MethodType,java.lang.invoke.MethodHandle,java.lang.invoke.MethodType)
  location: interface java.lang.invoke.LambdaMetafactory

I updated Android studio to the latest version but the issue remains. How can I fix this error? When I started the project I was using JDK 1.8 but due to adding kotlin or updating gradle I had to update it to JDK 11. Here is some additional info about app setup:

build.gradle (Project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.gradleVersion = '7.2.2'
    ext.kotlinVersion = '1.7.10'
    ext.rxJavaVersion = '3.0.3'

    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath "com.android.tools.build:gradle:$gradleVersion"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        
    }
}

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

build.gradle (Module:app)

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.myschedule"
        minSdk 27
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    sourceSets {
        main {
            assets {
                srcDirs 'src\\main\\assets'
            }
        }
    }
}

dependencies {

    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.6.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    implementation 'androidx.work:work-runtime:2.7.1'
    implementation 'androidx.work:work-multiprocess:2.7.1'
    implementation 'androidx.concurrent:concurrent-futures:1.1.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
    implementation "io.reactivex.rxjava3:rxjava:$rxJavaVersion"
    implementation 'androidx.preference:preference:1.2.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Lino
  • 5,084
  • 3
  • 21
  • 39
Kristian
  • 165
  • 2
  • 16
  • It's weird to me that you left the kotlinOptions that causes you to use 1.8 if you already moved to Java 11. Remove this, or change it to use Java 11 in build.gradle to see if it improves anything. Same for compileOptions. – mikehc Aug 14 '23 at 23:36

1 Answers1

0

I think a possible reason for this issue could be that the debugger and/or evaluator cannot handle the generation of code on the fly in the immediate window3.

Refer this link to know more for above reason

From the information you provided, it appears that your project is set up correctly to use lambda expressions, with both compileOptions and kotlinOptions set to use Java 1.8. However, it is possible that there may be some conflicts or issues with the version of Android Studio or the JDK that you are using.

One suggestion would be to try updating your JDK to the latest version and ensuring that Android Studio is also up to date.