NoClassDefFoundError的使用2.2.x的杰克逊在Android上有摇篮 [英] NoClassDefFoundError using Jackson 2.2.x on Android with Gradle

查看:349
本文介绍了NoClassDefFoundError的使用2.2.x的杰克逊在Android上有摇篮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我的Andr​​oid项目我成立了摇篮与杰克逊的2.2.x 如下:

For my Android project I set up Gradle with Jackson 2.2.x as follows:

// build.gradle
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 18
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:18.0.0'
    compile 'com.android.support:support-v4:18.0.0'
    compile 'com.google.android.gms:play-services:3.1.36'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.2.+'
    compile 'com.fasterxml.jackson.core:jackson-core:2.2.+'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.2.+'
}

我简单地使用 ObjectMapper 这里:

import com.fasterxml.jackson.databind.ObjectMapper;

// ...

ObjectMapper objectMapper = new ObjectMapper();
try {
    Content content = objectMapper.readValue(inputStream, Content.class);
} catch (IOException e) {
    e.printStackTrace();
}

当我运行摇篮installDebug 并启动它的应用程序崩溃的相关部分:

When I run gradle installDebug and launch the relevant part of the application it crashes:

java.lang.NoClassDefFoundError的:com.fasterxml.jackson.databind.ObjectMapper

java.lang.NoClassDefFoundError: com.fasterxml.jackson.databind.ObjectMapper

  • 我注意到,在错误信息 com.fasterxml.jackson ... 被提及,而 com.fasterxml.jackson.core build.gradle 。是否有不匹配导致的吗?
  • 我暂时搬到了依赖块到机器人块,因为我的found其他 build.gradle 配置这种方式构造。但它似乎没有什么区别。


Thoughts:

  • I noticed that in the error message com.fasterxml.jackson... is mentioned while com.fasterxml.jackson.core is defined in build.gradle. Is there a mismatch causing the problem?
  • I temporarily moved the dependencies block into the android block since I found other build.gradle configurations structured this way. However it seems to make no difference.
  • 推荐答案

    摇篮和Android并不总是很好地把具有相关性(还)。运行

    Gradle and Android don't always place nicely with dependencies(yet). Running

     gradle clean
    

    似乎解决了我最多的问题。

    seems to fix most problems for me.

    注意:的如果没有工作,你可以运行

    Note: If that didn't work, you can run

    dexdump classes.dex | grep 'Class descriptor'
    

    上的APK的classes.dex文件。这将检查如果类是包含在 classes.dex 文件。 (有时候,如果你想仔细检查怎么回事这是非常有用的)。

    on the classes.dex file in the APK. That will check to see if the class is included in the classes.dex file. (Sometimes it's useful if you want to double check whats going on).

    这篇关于NoClassDefFoundError的使用2.2.x的杰克逊在Android上有摇篮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆