android - 为什么 support-v4 依赖项未在我的自定义库中添加运行时
问题描述
我要制作自定义库。制作aar后,在另一个中导入,找不到支持依赖。
我的图书馆 Gradle 是:
dependencies {
implementation fileTree(include: ['*.jar'], exclude: ['classes2.jar'], dir: 'libs')
compileOnly files('libs/classes2.jar')
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:multidex:1.0.1'
}
解决方案
问题是因为您正在使用implementation
:
当您的模块配置实现依赖项时,它让 Gradle 知道该模块不想在编译时将依赖项泄漏给其他模块。也就是说,依赖项仅在运行时对其他模块可用。
模块依赖的自定义库不会看到支持库。所以,你需要使用api
:
当一个模块包含一个 api 依赖项时,它让 Gradle 知道该模块想要将该依赖项传递到其他模块,以便它们在运行时和编译时都可以使用它。此配置的行为就像 compile(现在已弃用),您通常应该只在库模块中使用它。
将您的依赖项块更改为如下内容:
dependencies {
implementation fileTree(include: ['*.jar'], exclude: ['classes2.jar'], dir: 'libs')
compileOnly files('libs/classes2.jar')
api 'com.android.support:support-v4:27.1.1'
api 'com.android.support:multidex:1.0.1'
}
推荐阅读
- javascript - 进行缓存的 Ajax 调用时如何避免竞争条件
- python-3.x - Python解析dict中的值
- amazon-web-services - 从 AWS Lightsail 运行 jupyter 笔记本时出现问题
- python - 获取 Keras 模型输出 wrt 输入的梯度,但最后一层是 SVM
- python - 使用查询集将过滤器应用于嵌套的反向外键关系
- linux - 在 Linux 内核中,task_struct 是在哪里初始化的?
- java - 如何使用 MSAL4J 获取守护程序的令牌?
- java - 设置 TextView 颜色的最有效方法
- javascript - 如何使用 observables 来更新上下文提供者以用于提供者组件(React/Firebase)?
- bash - 为什么从 shell 脚本创建 conda 环境会导致脚本提前终止,我该如何解决这个问题?