Android Studio 导入项目依赖(Gradle) 以 ArcGIS Android SDK 为例
date
‣
slug
Import-ArcGIS-Android-SDK-to-Intellij-IDEA
status
Published
tags
ArcGIS
Android
Intellij
summary
之前一直使用的 ADT + Intellij, 用起来也算安逸,导入导出依赖配置和 Eclipse 没什么区别。但是在多人协作开发时依赖的配置很麻烦。多次尝试切换到 Gradle 都出错告终。
大部分依赖提供jcenter 别名, 只要 在
build.gradle
的 dependencies
中添加
`compile 'com.jakewharton:butterknif...type
Post
之前一直使用的 ADT + Intellij, 用起来也算安逸,导入导出依赖配置和 Eclipse 没什么区别。但是在多人协作开发时依赖的配置很麻烦。多次尝试切换到 Gradle 都出错告终。
大部分依赖提供jcenter 别名, 只要 在
build.gradle
的 dependencies
中添加compile 'com.jakewharton:butterknife:6.0.0'
但是一些没有推送到 jcenter 的项目按照之前的
Import Module
导入时总会导致原先的项目混乱。参考 StackOverflow 上的一篇问答 “Import Module” changes structure of existing library
- Copied library’s directory under the root directory of my project.
- Referenced that library in settings.gradle by adding include ‘:libraryA’.
- Added dependency to my project’s build.gradle: compile project(‘:libraryA’).
ADT 模式下 Intellij 导入 ArcGIS Android SDK 的方式可以参考官方博客ArcGIS Android development with IntelliJ IDEA。
Gradle 方式官方在 GitHub 上有介绍 ArcGIS Android API Lib Module,但是说明版本太旧,按照说明无法导入。
下面是测试可行的导入方式
- 整个 Project 中有 三个
build.gradle
, 一个settings.gradle
每步需要的修改的依赖不能乱。配置之前记得把项目提交到 git 仓库, 万一出错checkout回来就好了。
- 获取依赖项目
可以直接下载
推荐使用 git
git clone git@github.com:Esri/arcgis-android-api-lib-module.git --depth=1
- 复制
arcgis-android-v10.2.4
到项目目录

settings.gradle
中添加include ':arcgis-android-v10.2.4'

- 要添加依赖的module的 build.gradle 中的
dependencies
添加compile project(":arcgis-android-v10.2.4")

- 其他注意 ArcGIS Android 10.2.4 (Gradle) 中
classpath 'com.android.tools.build:gradle:0.14.1'
版本为 0.14.1 对于 0.14.0 之后的版本 runProguard 替换为 minifyEnabled 如果你的版本低于14则 arcgis-android-v10.2.4 中的 build.gradle 中的 minifyEnabled()会提示找不到,只要替换就好。