对于我的 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...
中提到了 whilecom.fasterxml.jackson.core
is defined inbuild.gradle
. 是否存在不匹配导致问题? - 我暂时将
dependencies
块移动到android
块中,因为我发现其他build.gradle
配置以这种方式构造。不过好像没什么区别。