在应用程序中找不到传递库依赖项 [英] Transitive Library dependencies are not found in the application

查看:25
本文介绍了在应用程序中找不到传递库依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个库模块,其中包含一些像 OkHttp 这样的 3rd 方库.当我在我的应用程序中包含这个库时,我无法使用这些 3rd 方库.我阅读了以下文章 第 1 条第 2 条并尝试了
1. 编译项目(':library-name')
{将 .aar 文件(库的)作为模块导入 myproject 后}
2.我在libs文件夹中包含了.aar文件并添加了以下依赖

Say I have a library module which contains some 3rd party libraries like OkHttp. When I include this library in my application I was unable to use these 3rd party libraries. I read the following articles Article 1, Article 2 and tried
1. compile project(':library-name')
{after importing the .aar file(of library) as a module into myproject}
2. I included the .aar file in libs folder and added following dependencies

build.gradle(项目级别)

build.gradle(project level)

allprojects {
repositories {
    flatDir {
        dirs 'libs'
    }
}
}

build.gradle(应用层)

build.gradle(application level)

compile fileTree(dir: 'libs', include: ['*.jar'])
compile ('com.myapp.package:library-name:1.0.0@aar'){
transitive=true
}

3.类似于第二,但在
build.gradle(应用程序级别)

3. similar to 2nd but in
build.gradle(application level)

compile fileTree(dir: 'libs', include: ['*.jar'])
compile (name:'library-name', ext:'aar'){
transitive=true
}

但是,我仍然无法使用我的库中存在的传递库.我收到以下异常.

But, still I was unable to use the transitive libraries which are present in my library. I am getting following exception.

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/okhttp/MediaType;

有人可以帮忙吗


以下是我的库的build.gradle


The following is build.gradle of my library

compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'

compile 'org.apache.httpcomponents:httpcore:4.4.4'
compile 'org.apache.httpcomponents:httpclient:4.5.1'

compile 'com.squareup.okhttp:okhttp:2.6.0'
compile 'petrov.kristiyan.colorpicker:colorpicker-library:1.0.3'


testCompile 'junit:junit:4.12'

testCompile 'org.mockito:mockito-core:1.10.19'

testCompile 'org.hamcrest:hamcrest-library:1.1'

compile files('notificationlog-0.1.0.jar')

我能够在我的应用程序中使用 notificationlog,这是我的库中的一个依赖项,但我无法使用 okhttpcolorpicker>

I was able to use the notificationlog in my application which was a dependency in my library, but I was unable to use okhttp and colorpicker

推荐答案

aar 文件不包含嵌套(或 transitive) 依赖 并且没有描述使用的依赖的 pom 文件图书馆.

The aar file doesn't contain the nested (or transitive) dependencies and doesn't have a pom file which describes the dependencies used by the library.

这意味着,如果您使用 flatDir 存储库导入 aar 文件您还必须在项目中指定依赖项.

It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.

没有意义:

compile (name:'library-name', ext:'aar'){
    transitive=true
}

因为 aar 没有描述依赖的 pom 文件,所以 gradle 无法添加任何依赖,因为它不知道它们.

because the aar is without a pom file which describes the dependencies, then gradle is unable to add any dependencies because it can't know them.

这篇关于在应用程序中找不到传递库依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆