【问题标题】:No class found exception com.squareup.okhttp.logging.HttpLoggingInterceptor没有类发现异常 com.squareup.okhttp.logging.HttpLoggingInterceptor
【发布时间】:2020-01-30 16:18:17
【问题描述】:

即使在添加依赖项并导入类之后,我仍然收到 java.lang.NoClassDefFoundError: com.squareup.okhttp.logging.HttpLoggingInterceptor。

有人可以帮忙吗?

Gradle 构建文件

   apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "xyz"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    repositories {
        mavenCentral()
    }
 }

    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.google.code.gson:gson:2.4'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.facebook.android:facebook-android-sdk:4.1.0'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
    compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
    compile 'com.squareup.okhttp:logging-interceptor:2.6.0'
    }

【问题讨论】:

  • 你使用的是Android Studio还是eclipse?如果是 Android Studio,你使用的是 Gradle 吗?如果是,您可以将 Gradle 文件添加到您的问题中吗?
  • @cricket_007 已添加构建文件
  • 你能成功使用Gradle构建并检查所有的依赖都下载了吗?
  • 如何知道它是否正在下载依赖项,对不起,我是android新手。 @cricket_007
  • 没关系。在 Android Studio 的其中一个侧面板中,应该有一个带有绿色图标的 Gradle 按钮。从那里,应该有诸如 clean 和 installDependencies 和 build 的选项。然后在另一个窗格中(可能是您的文件所在的左侧),可能有一个用于引用库的折叠部分。

标签: android retrofit okhttp


【解决方案1】:

就我而言,我发现 okhttp3 和 okhttp3:logging-interceptor 依赖项的版本需要完全匹配。比如:

...
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
...

【讨论】:

    【解决方案2】:

    可能是改造的兼容性问题。

    尝试:

    implementation 'com.squareup.okhttp:logging-interceptor:2.5.0'
    

    这篇文章可能会有所帮助

    App crash on HttpLoggingInterceptor

    【讨论】:

      【解决方案3】:

      它也可以与您的 build.gradle 中的 multidex true 选项连接(是的,似乎某些设备在使用 multidex 应用程序时存在问题(阅读,三星))

      如果是这种情况,请关闭此标志并重新构建您的项目。考虑使用

      minifyEnabled true
      shrinkResources true
      

      减少您的 apk 大小。如果它仍然太大,那真的很奇怪和坏消息,但是有一些techniques to put your apk on diet

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-12-11
        • 2016-03-06
        • 2014-04-22
        • 2019-02-11
        • 2019-01-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多