Android

[Android] java.lang.NoSuchMethodError: No static method metafactory 해결 방법

elisom 2022. 2. 4. (Last updated:

java.lang.NoSuchMethodError: No static method metafactory 가 발생했다.

 

문제 상황

DataBinding을 이용해서 button에 setOnClickListener() 를 생성했는데 해당 에러가 발생했다.

 

java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.art/javalib/core-oj.jar)

 

해결 방법

build.gradle (Module: ...app) 에 다음과 같은 코드를 추가한다.

android {
    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}

 

참고:

https://stackoverflow.com/questions/59448845/no-static-method-metafactory

 

No static method metafactory

I have an issue with my app that when I log in, the app crashes and I get the error: java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;

stackoverflow.com