10
  1. 安装最新的 STS(目前为 3.4.0)
  2. 按照现有 IDE 的常规 Android 开发设置步骤在 STS 中设置您的 Android 开发环境:http: //developer.android.com/sdk/installing/index.html
  3. 对于上述步骤,您可以通过从另一个已经设置了环境的开发人员那里复制“android-sdk”文件夹来节省时间,并将您的 STS 指向该 android 文件夹(Window-->Preferences-->Android-->SDK地点)
  4. 按照以下方式安装 m2e-android:http ://rgladwell.github.io/m2e-android/

使用 Maven 创建示例 Android 应用程序

  1. 在 STS 中,点击 File-->New-->Maven Project
  2. 选择您的工作区位置,然后单击下一步
  3. 对于 Maven Archetype,选择“android-quickstart”并单击 Next。如果您根据以下内容添加原型,则此原型应该存在:http ://rgladwell.github.io/m2e-android/
  4. 填写所需的 Maven 项目详细信息,然后单击下一步。
  5. 在 pom.xml 中,将“platform.version”标记值设置为 4.1.1.4
  6. 右键单击项目并选择构建项目。
  7. 右键单击项目并选择 Run As  Android Application。
  8. 它应该启动您的 Android 模拟器并部署“Hello World”应用程序。

在 Android 应用程序中使用 Spring Android 库:

  1. 由于我们使用 Maven,请按照此处的说明配置您的依赖项:http ://projects.spring.io/spring-android
  2. 按原样使用上述依赖项似乎存在错误。尝试在 STS 中运行 Android 应用程序时出现错误,它显示“多个 dex 文件定义 Lorg/springframework/core/ErrorCoded”。这意味着在类路径中引用了重复的类。为避免此错误,请删除 maven 依赖元素“spring-android-auth”。

使用 Spring Android 库中的 RestTemplate:

  1. 参考文档为您提供所需的一切:http: //docs.spring.io/spring-android/docs/1.0.1.RELEASE/reference/html/rest-template.html
  2. 请记住,您的 Android 应用程序必须注册正确的消息转换器。例如:restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
  3. 请注意,您的 Android 应用程序必须包含使用权限“android.permission.INTERNET”以允许网络调用。
4

0 回答 0