我们知道gradle 3.xx更新了依赖配置,我在使用时有问题,我们知道如果项目使用v7:26.0.1,最好在库模块中使用相同的版本,所以我认为使用 compileOnly 是最好的选择,它会通过编译时间并在运行时使用app库的v7代码,它会减少apk大小并且不关心v7版本吗? 但是你试试,你会发现它无法通过编译时间,为什么?
这些是我得到的错误,它们都与xml没有找到值有关。
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').
答案 0 :(得分:1)
compileOnly
表示只编译它。在运行时的含义,当它需要AppCompat库时,它不存在,因为该库未添加到APK本身。
您可以使用像Lombok这样的库compileOnly
,因为在运行时不需要它 - 只需要编译时间。但是,在运行时也需要AppCompat。不要使用compileOnly
。如果您使用的是gradle版本,请使用implementation
(或compile
。
您可以使用compileOnly
关键字,例如注释库(如Lombok),因为通常在编译时删除对库的引用(并转换为非库代码)。当然有例外,但这是一个使用示例。
使用compileOnly
的APK较小,因为该库未添加到APK中。使用compileOnly
时,不能在运行时使用任何库功能,因为在运行时无法找到库