android - Gradle 中新的 Implement 关键字是什么

标签 android android-studio gradle

我最近将 Android studio 更新到了 3.0 版本。现在在build.gradle所有依赖项均使用 implementation 添加关键字而不是旧的 compile关键词。

dependencies {
     implementation fileTree(include: ['*.jar'], dir: 'libs')
     implementation 'com.android.support:appcompat-v7:25.4.0'
}

但是compile关键字仍然有效。 compile 和有什么不一样?和Implementation

最佳答案

compile 已被弃用,因此库使用 apiimplementation

Gradle 3.4 introduced new Java Library plugin configurations that allow you to control whether a dependency is published to the compile and runtime classpaths of projects that consume that library. The Android plugin is adopting these new dependency configurations, and migrating large projects to use them can drastically reduce build times.

实现

if an implementation dependency changes its API, Gradle recompiles only that dependency and the modules that directly depend on it. Most app and test modules should use this configuration.

api

When a module includes an api dependency, it's letting Gradle know that the module wants to transitively export that dependency to other modules, so that it's available to them at both runtime and compile time. This configuration behaves just like compile (which is now deprecated), and you should typically use this only in library modules. That's because, if an api dependency changes its external API, Gradle recompiles all modules that have access to that dependency at compile time

阅读 new dependency configurations的更多内容

关于android - Gradle 中新的 Implement 关键字是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47049984/

相关文章:

android - 如何在 Android Studio 中查找 Strings.xml 的用法?

Android Studio 2.0 - 带有 Gradle 的预览版 6

gradle - 如何在配置步骤中将Gradle属性设置为不同的值?

java - arraylist 未存储在 hashmap 中

安卓画图 PorterDuff.Mode.CLEAR

android - 资源$NotFoundException : String resource ID #0x0 with Toast. makeText

android - gradle dependencies 是否有一个选项只显示库列表

java - 如何在用户 map 缩放时调整多个圆的大小?

android - 如何在Google Play Game Service中获取排行榜和成就信息

java - Android studio “unfortunately [project name] stopped working”,有关如何修复的任何线索