我最近将 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
已被弃用,因此库使用 api
或 implementation
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/