在Android工作室的春季启动

时间:2017-01-13 19:27:34

标签: android spring-boot

在android studio build.gradle中使用spring boot的正确方法是什么? 这就是我正在使用的 -

apply plugin: 'com.android.application'
buildscript {
repositories {
    mavenCentral()
    mavenLocal()
    jcenter()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.3.RELEASE")
}
}
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
    applicationId "com.example.prateek.businesscardrest"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
    exclude 'META-INF/spring.schemas'
    exclude 'META-INF/spring.tooling'
    exclude 'META-INF/INDEX.LIST'
    exclude 'META-INF/spring.handlers'
}
configurations {
    all*.exclude module: 'classworlds'
    all*.exclude module: 'commons-logging'
    all*.exclude module: 'httpclient'
    all*.exclude module: 'maven-artifact'
    all*.exclude module: 'maven-artifact-manager'
    all*.exclude module: 'maven-error-diagnostics'
    all*.exclude module: 'maven-model'
    all*.exclude module: 'maven-project'
    all*.exclude module: 'maven-settings'
    all*.exclude module: 'plexus-container-default'
    all*.exclude module: 'plexus-interpolation'
    all*.exclude module: 'plexus-utils'
    all*.exclude module: 'wagon-file'
    all*.exclude module: 'wagon-http-lightweight'
    all*.exclude module: 'wagon-provider-api'

}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.2'
compile 'org.springframework:spring-web:3.1.1.RELEASE'
compile 'com.google.code.findbugs:jsr305:2.0.1'
testCompile 'junit:junit:4.12'
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
    exclude module: "spring-boot-starter-tomcat"
}

}

但这会产生错误 - 错误:无法解决:org.springframework.boot:spring-boot-starter-web

2 个答案:

答案 0 :(得分:1)

另一个答案假设他正在使用Spring for Android,但我认为他不在我的回答中。所以,我认为OP正在尝试做的是在Android Studio中安装Android应用程序的后端模块并希望独立于App部署该模块。

现在事情变得有意义了,这就是你需要添加的依赖项:

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:1.5.3.RELEASE")
}

请注意,只是为spring-boot添加插件不利于实际的Spring-boot框架,你必须在依赖项中添加它。

答案 1 :(得分:0)

Spring Boot 意味着在Android应用生产中使用,因为它最适合用于构建Web应用程序。

但是,Spring for Android存在,但使用仅限于REST客户端和API身份验证。