Android Studio 3 发布有段时间了,之前看到的是测试版就一直用着 2.2.3 没更新。前段时间项目模块升级,Android Studio 的更新提示已经是 3.0.1 正式版了,于是就对开发环境也做了一次升级。本文说几点 Android Studio 3.0.1 的几点变化,不是全面介绍 Android Studio 3 的新特性,而是一些项目迁移过程中感受到的 Android Studio 3.0.1 相对于 Android Studio 2.2.3 的几点变化。

It's about the network
Android Studio 3.0.1

自带 OpenJDK

Android Studio 3.0.1 已经自带了 JDK,不需要安装 JDK 即可以正常运行。adb 程序也可以独立运行(不需要打开 Android Studio,不需要安装 JDK)。安装 Android Studio 后只需要下载必要的 sdk 即可。

It's about the network
Android Studio 3.0.1 自带 JDK

打开 “Project Structure” 选项可以看到 JDK 相关的设置,这里可以看到 “Use embedded JDK(recommended)” 即“使用内置的 JDK(推荐)”默认处于勾选状态,并且下方有 jre 的路径(Android Studio 位于 D:\AndroiDev\android-studio)。再到 D:\AndroiDev\android-studio\jre 下查看 java 版本,显示 OpenJDK

It's about the network
JDK 默认设置

快速文档

按 Ctrl+Q 即会弹出鼠标所选内容的技术文档,该功能在 Android Studio 2.2.3 时加载文档很慢,看一个 Method 的文档等上几十秒都有可能。StackOverFlow 上有人找到了原因并给出了解决方法(快速文档功能首先会尝试打开在线内容,没有在线内容再使用本地,有些区域无法连接在线文档,即导致文档加载慢的问题,修改 jdk.table.xml 指向本地文档可解决)。这一问题在 Android Studio 3.0.1 里已经不存在了,SDK 里安装 “Documentation for Android SDK” 看文档 Ctrl+Q 秒开。

It's about the network
离线文档

模块依赖

你可能已经发现,Android Studio 3.0.1 项目模块的 build.gradle 里 dependencies 配置已经从旧版的 “compile” 变成了 “implementation”。
比如:compile fileTree(dir: 'libs', include: ['*.jar'])
变为:implementation fileTree(dir: 'libs', include: ['*.jar'])
对于这样的变化,gradle 官方文档有解释,章节 49.2 提到 “compile” 配置目前存在但不应当再使用,应当使用 “api” 或 “implementation”,还说明了两者的区别。官方原文:java_library_separation

The plugin exposes two configurations that can be used to declare dependencies: api and implementation. The api configuration should be used to declare dependencies which are exported by the library API, whereas the implementation configuration should be used to declare dependencies which are internal to the component.

(翻译)插件公开了两种可用于声明依赖项的配置: “api” 和 “implementation”。“api” 配置应当用于声明由库 API 导出的依赖项, 而 “implementation” 配置应当用于声明组件内部的依赖项。

Note: The compile configuration still exists but should not be used as it will not offer the guarantees that the api and implementation configurations provide.

(翻译)注意:“compile” 配置仍然存在,但不应使用,因为它不会提供的 “api” 和 “implementation” 配置所提供保障。

就是说,如果不想让依赖项暴露给外部(让外部不可调用)则使用 implementation,估计这个配置适用大部分情况。如果模块的依赖项目需要给外部使用则用 “api”。