【问题标题】:Why support-v4 dependency not added runtime in my Custom Library为什么 support-v4 依赖项未在我的自定义库中添加运行时
【发布时间】:2018-06-21 05:51:33
【问题描述】:

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

【问题讨论】:

    标签: android android-gradle-plugin android-library


    【解决方案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'
    }
    

    【讨论】:

    • 还有一个问题,我的自定义库 /res/xml/provider_paths.xml 没有与 aar 文件绑定。请帮助我。
    猜你喜欢
    • 2015-12-21
    • 2020-04-16
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多