NoClassDefFoundError uses Jackson 2.2 X with gradle on Android

For my android project, I set gradle with Jackson 2.2 X is 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.+'
}

I just use objectmapper here:

import com.fasterxml.jackson.databind.ObjectMapper;

// ...

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

When I run gradle installdebug and start the relevant part of the application to crash:

reflection:

>I noticed that in build Gradle defines com fasterxml. jackson. Com. Is mentioned in the error message of core fasterxml. jackson …. Are there any mismatches that cause problems? > I temporarily moved this dependency block to the Android block because I found other build Gradle configurations are structured like this But there seems to be no difference

Solution

Gradle and Android don't always have a good dependency function

gradle clean

Seems to have solved most of my problems

Note: if not, it can run

dexdump classes.dex | grep 'Class descriptor'

Classes in APK In the DEX file This will check whether the class is included in classes In the DEX file (sometimes this is useful if you want to examine what is happening carefully)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>