- Install latest STS (currently 3.4.0)
- 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
- 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)
- Install m2e-android as per: http://rgladwell.github.io/m2e-android/
Create a sample Android application using Maven
- In STS, click on File-->New-->Maven Project
- Select your workspace location and Click Next
- 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/
- Fill in your desired Maven project details and click Next.
- In pom.xml, set the "platform.version" tag value to 4.1.1.4
- Right click on the project and select Build Project.
- Right click on the project and select Run As Android Application.
- It should start up your Android emulator and deploy the ‘Hello World’ application.
Making use of Spring Android libraries in an Android application:
- As we are using Maven, follow the instructions here to configure your dependencies: http://projects.spring.io/spring-android
- 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:
- The reference documentation gives you everything you need: http://docs.spring.io/spring-android/docs/1.0.1.RELEASE/reference/html/rest-template.html
- Remember that your Android application must register the correct message converter. Eg: restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
- Note that your Android application must include uses-permission “android.permission.INTERNET” to allow network calls.
spring-android-auth
itself, rather the transitive dependency tospring-security-crypto
. It depends onspring-core
, which should be excluded for an Android environment. – Danettedaney