2016-04-20 101 views
0

我在第一次尝试我的手在android开发中,并且我想创建一个应用程序“MyFirstApp”,它将调用REST服务。我做了一些研究,看起来Spring for Android是一个很好的帮助我的工具。我从来没有用过Spring,但我对Android Studio还不是很熟悉,所以我很困惑我应该如何将Spring的依赖项添加到我的项目中。将Android for Android添加到Android Studio项目

Spring的网站上有一段代码,他们说要复制并粘贴到我的依赖关系:

dependencies { 
    compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3' 
}repositories { 
    maven { 
     url 'https://repo.spring.io/libs-milestone' 
    } 
} 

我知道已经有发布了一个问题,解决一个非常类似的问题,但我需要帮助确切地知道哪些文件将上面的代码添加到,并确切地在那里。

我有两个在我的项目中创建的“build.gradle”文件。首先是

的build.gradle(模块:APP)

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.2" 

    defaultConfig { 
     applicationId "com.example.owner.myfirstapp" 
     minSdkVersion 15 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.1.1' 
    compile 'com.android.support:design:23.1.1' 
} 

其次是的build.gradle(项目:MyFirstApp)

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:1.5.0' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 

    dependencies { 
     compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3' 
    }repositories { 
     maven { 
      url 'https://repo.spring.io/libs-milestone' 
     } 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

谁能帮给我看在这两个文件,我应该包括Spring依赖?我非常感谢任何帮助。

回答

0

我不知道,如果你是在防火墙后面,所以这应该真正做到了建议,但需要出示格式化代码: 尝试以http这里更换的https:

maven { 
    url 'http**s**://repo.spring.io/libs-milestone' 
} 

,并添加一个网址对于jcenter:

repositories { 
     jcenter { 
      url "http://jcenter.bintray.com/" 
     } 
    } 
0

build.gradle (Module: app)添加这里面dependencies

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

build.gradle(Project: MyFirstApp)添加这里面repositories

maven { 
      url 'https://repo.spring.io/libs-milestone' 
     } 

就是这样。你已准备好出发。

0

您的依赖下build.gradle(Module:app)添加compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3',然后行家块:

maven { 
    url 'https://repo.spring.io/libs-milestone' 
} 

放在下面设置的依赖块大括号的allprojects。