1
0

More than 3 years have passed since last update.

OkHttp の Intercepter で出るエラー( java.lang.NoSuchMethodError: No static method metafactory )

Last updated at Posted at 2020-05-02

背景

MVVM の復習のために久しぶりに github API を Retrofit2 でたたくサンプルアプリを作成していた。

参考サイト https://tech.mti.co.jp/entry/2020/03/31/163321

エラーの内容

こんな感じのエラーが出てくる

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.runtime/javalib/core-oj.jar)
        at okhttp3.internal.Util.<clinit>(Util.java:87)
        at okhttp3.internal.Util.skipLeadingAsciiWhitespace(Util.java:321)

解決策

これを Gradle (Module:app) に追加したら行ける

build.dradle
android {

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

    kotlinOptions {
        jvmTarget = "1.8"
    }
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0