Prateek Sharma
Prateek Sharma

Reputation: 21

spring boot in android studio

What is the correct way of using spring boot in android studio build.gradle? This is what I am using-

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"
}

}

But this generates an error- Error:Failed to resolve: org.springframework.boot:spring-boot-starter-web

Upvotes: 1

Views: 17156

Answers (2)

Manish Kumar Sharma
Manish Kumar Sharma

Reputation: 13432

The other answer assumes that he is using Spring for Android but I assume he is not in my answer. So, I think what OP is trying to do is running a backend module side by side of the Android App in Android Studio and wants to deploy this module independently of the App.

Now that the things makes sense, here is what you need to add as a dependency:

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

Note that just adding the plugin for spring-boot does not facilitate the actual Spring-boot framework, you have to add it in the dependency.

Upvotes: 1

cipley
cipley

Reputation: 1112

Spring Boot is not meant to be used in Android Apps production as it was best used to build web applications.

There exists, however, Spring for Android, but the use is limited to REST Client and API authentications.

Upvotes: 0

Related Questions