How to setup an Android development environment using STS, Android SDK, Maven and Spring Android
Asked Answered
H

0

10
  1. Install latest STS (currently 3.4.0)
  2. Setup your Android development environment in STS as per the normal Android development setup steps for an existing IDE: http://developer.android.com/sdk/installing/index.html
  3. For the above step, you could save time by copying the “android-sdk” folder from another developer who has already setup their environment, and point your STS to that android folder (Window-->Preferences-->Android-->SDK Location)
  4. Install m2e-android as per: http://rgladwell.github.io/m2e-android/

Create a sample Android application using Maven

  1. In STS, click on File-->New-->Maven Project
  2. Select your workspace location and Click Next
  3. For the Maven Archetype, select “android-quickstart” and click Next. This archetype should exist if you added the Archetype according to: http://rgladwell.github.io/m2e-android/
  4. Fill in your desired Maven project details and click Next.
  5. In pom.xml, set the "platform.version" tag value to 4.1.1.4
  6. Right click on the project and select Build Project.
  7. Right click on the project and select Run As  Android Application.
  8. It should start up your Android emulator and deploy the ‘Hello World’ application.

Making use of Spring Android libraries in an Android application:

  1. As we are using Maven, follow the instructions here to configure your dependencies: http://projects.spring.io/spring-android
  2. There seems to be an error is using the above dependencies as is. The error is given when trying to run the Android application in STS, it says “Multiple dex files define Lorg/springframework/core/ErrorCoded”. This means that duplicate classes are referenced on the classpath. To avoid this error, remove the maven dependency element “spring-android-auth”.

Using RestTemplate from the Spring Android libraries:

  1. The reference documentation gives you everything you need: http://docs.spring.io/spring-android/docs/1.0.1.RELEASE/reference/html/rest-template.html
  2. Remember that your Android application must register the correct message converter. Eg: restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
  3. Note that your Android application must include uses-permission “android.permission.INTERNET” to allow network calls.
Hinz answered 10/3, 2014 at 6:56 Comment(2)
Do you have a question regarding these instructions? Note the dependency issue is not with spring-android-auth itself, rather the transitive dependency to spring-security-crypto. It depends on spring-core, which should be excluded for an Android environment.Danettedaney
Thanks Roy. No, I dont have any questions, but I created a basic HOWTO for others at work and thought I'd post it here for others to use.Hinz

© 2022 - 2024 — McMap. All rights reserved.