【问题标题】:Spring Android not working with GradleSpring Android 无法与 Gradle 一起使用
【发布时间】:2014-01-20 21:14:30
【问题描述】:

我正在尝试在我的项目中使用 Spring Framework for Android。我正在使用带有 Gradle 构建工具的 IntelliJ。我正在关注春季快速入门教程。 我的 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 import org.springframework.web.client.RestTemplate;

【问题讨论】:

  • org.springframework.web.client.RestTemplate 不在你的类路径中
  • @Amith 如何在 intelliJ 中解决这个问题?
  • IntelliJ 的哪个版本?
  • @ben75 版本 13.0.1
  • 我终于通过运行:Gradle clean task 和 Sync Project with Gradle Files 使其工作。

标签: java android spring gradle


【解决方案1】:

对于遇到同样问题的人。就我而言,问题是这样的:我的项目中有一个库,它有 spring 作为依赖项,所以在它的 build.gradle 中,有这样一行:

compile 'org.springframework.android:spring-android-rest-template:2.0.0.M1'

但是对于一些神秘的(我真的不知道为什么),我可以解决问题的唯一方法是在我的根模块中添加上述依赖项。起初,这个依赖项不在我的根模块中,因为只有提到的库使用 RestTemplate 类。

【讨论】:

  • 如何在根模块中添加这个依赖??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-15
  • 2017-03-21
  • 2017-08-31
  • 2017-03-21
  • 2011-01-23
  • 2020-03-09
相关资源
最近更新 更多