为什么不在我的自定义库中添加 support-v4 依赖项运行时
Why support-v4 dependency not added runtime in my Custom 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'
}
问题是因为您使用的是 implementation
:
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.
将依赖块更改为如下内容:
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'
}
我要制作自定义库。制作完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
:
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.
将依赖块更改为如下内容:
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'
}