对于我的Android项目,我使用Jackson
2.2.x设置了Gradle,如下所示:
// 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();
}
当我运行gradle installDebug并启动应用程序的相关部分时,它崩溃了:
java.lang.NoClassDefFoundError:com.fasterxml.jackson.databind.ObjectMapper
想法:
我注意到在com.fasterxml.jackson...中com.fasterxml.jackson.core定义时,在错误消息中提到了该消息build.gradle。是否存在引起问题的不匹配?
由于我发现以这种方式构造的其他配置,因此我将dependencies块暂时移入了该android块。但是,似乎没有什么区别。build.gradle