我正在尝试在我的项目中使用适用于 Android 的 Spring 框架。我正在使用 IntelliJ 和 Gradle 构建工具。我正在关注 Spring 快速入门教程。 我的 gradle.build 文件:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile 'com.android.support:appcompat-v7:19.0.0'
compile "joda-time:joda-time:2.2"
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
compile 'org.springframework.android:spring-android-auth:1.0.1.RELEASE'
compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
}
当我尝试这样做时:
new Thread(new Runnable() {
public void run() {
RestTemplate rest = new RestTemplate();
}
}).start();
我得到:
java.lang.NoClassDefFoundError: org.springframework.web.client.RestTemplate
我的进口中有 Ofc
导入org.springframework.web.client.RestTemplate;
最佳答案
对于遇到同样问题的人。就我而言,问题是这样的:我的项目中有一个库将 spring 作为依赖项,因此在其 build.gradle 中,有这一行:
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M1'
但是对于一些神秘的(我真的不知道为什么),我解决问题的唯一方法是在我的根模块中添加上述依赖项。起初,这个依赖项不在我的根模块中,因为只有提到的库使用 RestTemplate 类。
关于java - Spring Android 无法与 Gradle 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20899620/