【问题标题】:Android Glide library NoClassDefFoundErrorAndroid Glide 库 NoClassDefFoundError
【发布时间】:2015-07-14 04:59:30
【问题描述】:

我是否错误地使用了 Glide 库?可能是什么问题?

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ImageView iv = (ImageView) findViewById(R.id.imageView1);

    Glide.with(this).load(R.drawable.salads_caesar_salad).into(iv);
}

【问题讨论】:

  • 显示你的 Gradle 依赖项
  • @EpicPandaForce 说 LogCat 截图是 Ecipse LogCat 视图,我不认为 Gradle 在这里涉及。此外,应用程序正在运行,因此它必须位于编译类路径中。

标签: java android packaging android-glide


【解决方案1】:

如果您的代码编译良好,那么您很可能对编译类路径具有正确的依赖关系。如果您使用 Android Studio/Gradle,ProGuard 可能会出于某种原因以某种方式剥离 Glide 类,但实际上不应该,因为您实际上正在使用它。

上述矛盾以及您的 LogCat 屏幕截图是 Eclipse ADT 或 Android Device Monitor (monitor.bat) 的事实留下了一个选择:您没有export your dependency;尝试以下操作(请参阅链接手册中的屏幕截图):

  1. 右键单击 Android 应用程序项目
  2. 属性
  3. Java 构建路径
  4. 订购和出口
  5. 确保勾选glide.jar

或者考虑在 Android Studio(用于 Android 开发的官方 Google 产品)或 IntelliJ IDEA 14+ 中重新创建您的项目,然后复制您的源代码;与 Eclipse ADT 相比,IntelliJ Android 插件对 Android 和现代构建工具的支持要好得多。我本人确实反对过渡,但正如您所见,它奏效了,因为现在我正在提倡它。从长远来看,这值得一两天的努力。

【讨论】:

    【解决方案2】:

    您需要将 Glide 库添加到您的 android 项目中。

    如果你使用 gradle:

    dependencies {
        compile 'com.github.bumptech.glide:glide:3.6.0'
        compile 'com.android.support:support-v4:19.1.0'
    }
    

    如果你使用的是 maven:

    <dependency>
      <groupId>com.github.bumptech.glide</groupId>
      <artifactId>glide</artifactId>
      <version>3.6.0</version>
      <type>aar</type>
    </dependency>
    <dependency>
      <groupId>com.google.android</groupId>
      <artifactId>support-v4</artifactId>
      <version>r7</version>
    </dependency>
    

    您还可以在Eclipse 中将库直接添加到您的项目中:右键单击项目的属性,然后单击“库”部分,然后单击“添加”以添加库。

    如果您使用的是Android Studiohttp://www.truiton.com/2015/02/android-studio-add-library-project/

    【讨论】:

      【解决方案3】:

      您似乎错误地导入了 glide 库 -

      android 的 NoClassDefFoundError 结果 build 没有找到你的 glide 库。

      在 android studio 中,您可以通过添加 库滑动到您的依赖项。 查看大体攻略here

      【讨论】:

        【解决方案4】:

        我认为您只能加载 URL,并且您只能根据其文档在 .error() 和 .placeholder() 方法中使用资源。 https://github.com/bumptech/glide

        当你可以像这样直接在 imageview 中设置资源时,为什么还要使用 glide:

        iv.setImageResource(R.drawable.salads_caesar_salad);
        

        希望对你有帮助!

        【讨论】:

          猜你喜欢
          • 2016-09-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-04
          • 2013-05-13
          • 1970-01-01
          • 1970-01-01
          • 2011-12-21
          相关资源
          最近更新 更多