【问题标题】:java.lang.NoClassDefFoundError: Failed resolution of: Lcom/bumptech/glide/Glide; Runtime Errorjava.lang.NoClassDefFoundError:解析失败:Lcom/bumptech/glide/Glide;运行时错误
【发布时间】:2017-08-03 11:47:05
【问题描述】:

我正在使用最新的Glide Android 库。在编译时没有错误,但是当应用程序安装在设备上时,它会在运行时显示此错误:

java.lang.NoClassDefFoundError:解析失败: Lcom/bumptech/glide/滑翔;

我在Glide官方Github页面中包含了以下模块:

compile 'com.github.bumptech.glide:glide:4.0.0' compile 'com.android.support:support-v4:25.3.1' annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'

错误仍然存​​在。

Glide Github Link

构建.gradle:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
    dexOptions {
        javaMaxHeapSize "4g"
        preDexLibraries = false
    }

    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "com.esmartify"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true

    }
    buildTypes {
        release {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            minifyEnabled false
        }
    }
}

dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:support-vector-drawable:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.google.android.gms:play-services:11.0.2'
    compile 'com.firebase:geofire-android:2.1.1'
    compile 'com.firebaseui:firebase-ui-auth:2.0.1'
    compile 'com.facebook.android:facebook-android-sdk:4.22.1'
    compile 'com.google.firebase:firebase-auth:11.0.1'
    compile 'com.google.firebase:firebase-crash:11.0.1'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.google.android.gms:play-services-maps:11.0.2'
    testCompile 'junit:junit:4.12'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
    debugCompile 'com.facebook.stetho:stetho:1.5.0'
    debugCompile 'com.uphyca:stetho_realm:2.1.0'
}
apply plugin: 'com.google.gms.google-services'

编辑:我认为问题出在其他地方,因为使用 Picasso 而不是 Glide 会引发与 Picasso java.lang.NoClassDefFoundError 相同的错误

【问题讨论】:

  • 看起来是版本依赖错误
  • compile 'com.android.support:appcompat-v7:25.3.1' 尝试使用 v7
  • 我已经尝试了所有可能的版本组合。还是没有成功
  • @sagarsuri 是的,我也有这个。
  • 它是否在 logcat 中的 Activity 中显示任何行?

标签: android android-glide


【解决方案1】:

我也遇到了同样的问题,添加了transitive = true 字段就可以了

compile ('com.github.bumptech.glide:glide:4.4.0@aar') {
    transitive = true
}

【讨论】:

    【解决方案2】:

    检查您是否在 build.gradle 文件中添加了 mavenCentral()

    repositories {
      mavenCentral()
    }
    

    【讨论】:

    • 是的,我在 build.gradle 中有 mavenCentral()。在编译期间 Glide 被识别并且没有编译错误。只有在运行时才会识别 Glide。
    • 让我再试一次让你知道
    • 当然!在过去的两天里,我一直坚持这一点。谢谢!
    • 您能否创建一个示例项目并将其托管在 github 或其他我们可以查看的地方,因为对我来说它工作正常。
    • 我尝试将 Glide 替换为 Picasso。错误仍在说,但这次说 Picasso ClassDefNotFound !!
    【解决方案3】:

    尝试将以下行添加到您的 proguard-rules.pro;

    -keep class com.bumptech.** {*;}
    -keepclassmembers class com.bumptech.** {*;}
    

    【讨论】:

      【解决方案4】:

      似乎您的项目中已经有了这个 glide 版本或类,因此您没有收到类定义错误。尝试使用 jdgui 检查所有依赖项 jar 类。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-28
        • 1970-01-01
        相关资源
        最近更新 更多