本文介绍了传递库依赖关系在应用程序中找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 假设我有一个包含OkHttp等第三方库的库模块。当我将这个库包含在我的应用程序中时,我无法使用这些第三方库。我阅读了以下文章第1条, 第2条 并尝试 。编译项目(':library-name') {将作为模块的.aar文件导入myproject之后} 2.我将.aar文件包含在libs文件夹中,并添加了以下依赖项: uild.gradle(项目级别) allprojects { repositories { flatDir { dirs'libs'} } } build.gradle(应用程序级别) compile fileTree(dir:'libs',include:['* .jar']) compile('com.myapp.package:library-name :1.0.0@aar'){ transitive = true } 3。类似于第二,但在 build.gradle(应用程序级别) compile fileTree(dir:'libs ',包括:['* .jar']) compile(名称:'library-name',ext:'aar'){ transitive = true } 但是,我仍然无法使用库中存在的传递库。 java.lang.NoClassDefFoundError:失败的解决方法:Lcom / squareup / okhttp / MediaType; 有人可以帮忙吗? 编辑:以下是我的库的build.gradle 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' 编译文件('notificationlog-0.1。 0.jar') 我可以使用 notificationlog 在我的应用程序中,这是我的库中的依赖项,但我无法使用 okhttp 和 colorpicker 解决方案 aar 文件 doesn' t包含嵌套(或传递)依赖关系,并且没有描述库使用的依赖关系的pom文件。 这意味着,如果您要使用 flatDir repo 您必须在您的项目中指定依赖关系。 没有意义: $ b $ pre $ compile(name:'library-name',ext:'aar'){ transitive = true } 因为aar没有描述依赖关系的pom文件, gradle无法添加任何依赖项,因为它无法知道它们。 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 2and tried1. 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 dependenciesbuild.gradle(project level) allprojects {repositories { flatDir { dirs 'libs' }}}build.gradle(application level) compile fileTree(dir: 'libs', include: ['*.jar'])compile ('com.myapp.package:library-name:1.0.0@aar'){transitive=true}3. similar to 2nd but inbuild.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;Can someone helpEDIT:The following is build.gradle of my librarycompile 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')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 解决方案 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.It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.It doesn't make sense:compile (name:'library-name', ext:'aar'){ transitive=true}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. 这篇关于传递库依赖关系在应用程序中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!