【问题标题】:java.lang.NoSuchMethodError: No static method get(Ljava/lang/String;)Lokhttp3/HttpUrl; in class Lokhttp3/HttpUrl; or its super classesjava.lang.NoSuchMethodError: 没有静态方法 get(Ljava/lang/String;)Lokhttp3/HttpUrl;在 Lokhttp3/HttpUrl 类中;或其超类
【发布时间】:2021-10-17 05:58:23
【问题描述】:

在集成Small case Library 之前,我的项目运行良好。集成后,我在安装应用程序时收到此错误。

java.lang.NoSuchMethodError: No static method get(Ljava/lang/String;)Lokhttp3/HttpUrl; in class Lokhttp3/HttpUrl; or its super classes (declaration of 'okhttp3.HttpUrl' appears in /data/app/base.apk!classes3.dex)
        at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:506)

我在这里附加应用级 gradle 文件。

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'


android {
    compileSdkVersion 29
    packagingOptions {
        exclude 'META-INF/*'
    }
    defaultConfig {
       
        minSdkVersion 23
        targetSdkVersion 29
       
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    configurations{
        all*.exclude module: 'okhttp'
        all*.exclude module: 'okio'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }




    buildToolsVersion '29.0.2'

}




dependencies {
    implementation project(path: ':library')
    implementation project(path: ':library')
    implementation project(path: ':library')
    testImplementation 'junit:junit:4.12'
 
    implementation 'com.smallcase.gateway:sdk:2.9.3'

    implementation ('com.squareup.retrofit2:retrofit:2.9.0') {
        exclude module: 'okhttp'
    }
    implementation 'com.google.code.gson:gson:2.6.2'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
    implementation 'com.squareup.okhttp3:okhttp:3.4.1'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.4.1'
   

}

正如其他答案中提到的,我已经尝试使用 Java 1.8 设置 CompileOptions。但没有运气。任何帮助将不胜感激。

【问题讨论】:

  • 您正在强制使用旧版本的 okhttp,这会破坏事物。您应该使用 3.12.13 或 4.9.1。

标签: android gradle retrofit okhttp


【解决方案1】:

同时使用最新版本(Retrofit 和 OkHttp)

https://github.com/square/retrofit/issues/3058

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
  • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
猜你喜欢
  • 2020-06-21
  • 2021-01-28
  • 1970-01-01
  • 2016-02-07
  • 1970-01-01
  • 2014-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多