Android Studio 3 和 Gradle 4.3 -> 库模块不再处理本地 JAR -> 如何处理?

Android Studio 3 and Gradle 4.3 -> Library modules no longer process local JARs -> how to handle this?

升级到AndroidStudio 3.0.0提到了这个,并没有详细说明如何处理:

Library modules no longer process local JARs. This is to speed up incremental builds that are caused by changes to a library module's code.

所以我有一个项目,里面有一个库项目。在我的图书馆项目的 build.gradle 文件中,我有这个:

compile files('libs/com.somelib.somepackage.jar')

我将 compile 更改为 implementation,当我尝试 运行 我的应用程序时,我所有试图访问 import com.somelib.somepackage.SomeClass 导入语句的 类抛出此包不存在的错误。

我改回 compile 并且能够构建 运行 我的应用程序。

我想遵守新规则,因为 compile 已弃用并将在下一个 Gradle 版本中删除,那么我该怎么做呢?

如果您尝试从应用程序项目的库项目中包含的 .jar 访问 类,则必须使用 api 而不是实现,否则 类 将只能在库项目中访问:

implementation files('libs/com.somelib.somepackage.jar')

应该是

api files('libs/com.somelib/somepackage.jar')

如文档所述:

... 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 ...

参考: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations