android - 为什么不在我的自定义库中添加 support-v4 依赖项运行时

标签 android android-gradle-plugin android-library

我要制作自定义库。制作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'
}

最佳答案

问题是因为您正在使用实现:

When your module configures an implementation dependency, it's letting Gradle know that the module does not want to leak the dependency to other modules at compile time. That is, the dependency is available to other modules only at runtime.

依赖自定义库的模块将看不到支持库。所以,你需要使用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.

将依赖 block 更改为如下内容:

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'
}

关于android - 为什么不在我的自定义库中添加 support-v4 依赖项运行时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50961227/

相关文章:

Android Studio同时为同一个项目构建两个应用

android - 同时安装两个具有相同代码库的 Android 目标

c# - 多平台支持的 WCF Restful 服务文件上传

android - 在 Android 应用程序中更改对象的颜色

android - 类别偏好后的 Material 分隔线

android - 我们可以在android VideoView中播放.swf文件吗?

android - ActivityTestRule 未导入

java - Android Studio - 资源条目已定义

android - list 合并失败:使用cardview 25.3.1的图书馆,我的应用使用25.00.alpha1

android - 以开发人员身份为应用启用家庭图书馆 : Android