我们知道gradle 3.x.x更新了依赖配置,我在使用的时候有一个问题,我们知道如果项目使用v7:26.0.1,最好在库模块中使用相同的版本,所以我认为使用 compileOnly 是最好的选择,它会通过编译时间并在运行时使用应用程序库的 v7 代码,它会减少 apk 大小并且不关心 v7 版本,对吧? 但是你试试看,你会发现编译不过关,为什么呢?
这些是我遇到的错误,它们都与 xml not finding values 有关。
Error:(43) No resource identifier found for attribute 'srcCompat' in package 'com.yalantis.ucrop.test'
Error:(19, 20) No resource found that matches the given name (at 'style' with value '@style/TextAppearance.Widget.AppCompat.Toolbar.Title').
最佳答案
compileOnly
表示只编译。这意味着在运行时,当它需要 AppCompat 库时,它不存在,因为该库没有添加到 APK 本身。
您可以对像 Lombok 这样的库执行 compileOnly
,因为它在运行时不需要 - 仅在编译时需要。但是,在运行时也需要 AppCompat。不要对它使用 compileOnly
。使用 implementation
(或者 compile
,如果你有使用它的 gradle 版本)。
您可以使用 compileOnly
关键字,例如注释库(如 Lombok),因为对库的引用通常在编译时删除(并转换为非库代码)。当然也有异常(exception),但这是一个用法示例。
使用 compileOnly
的 APK 更小,因为库没有添加到 APK 中。使用 compileOnly
时不能在运行时使用任何库功能,因为在运行时找不到库
关于android - 为什么 appcompat-v7 不能在库模块中使用 compileOnly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47881814/