問題描述
我們正在制作一些庫,主要是為了我們的 API,我們將使我們的外部開發(fā)人員的生活更輕松.
We're making some library, basicly for our API, that we would make life easier for our external developers.
所以我們創(chuàng)建了新的庫項目,并將 Retrofit 和其他一些庫作為依賴項.
So we created new library project and put Retrofit and some other libraries as dependencies.
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
現(xiàn)在當我們構(gòu)建它時,它會生成 aar
文件.
Now when we build it, it produces aar
file.
但是現(xiàn)在當我們把 aar
文件放到 libs
目錄并設(shè)置為依賴時,我們?nèi)匀恍枰谟脩舻?build.gradle 中放入相同的依賴
文件,這很糟糕.應該是從圖書館拿的吧?
But now when we put the aar
file to libs
directory and set it as dependency, we still have to put the same dependency in user's build.gradle
file, which sucks. It should be taken from the library, right?
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name: 'ourlibrary', ext: 'aar') {
transitive = true;
}
}
如何使 transitive = true
工作?
推薦答案
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.
在您的情況下,由于上述原因,添加 transitive=true
并不能解決您的問題.
In your case adding transitive=true
doesn't resolve your issue for the reason described above.
您應該使用 ma??ven 存儲庫(您必須在私有或公共 maven 存儲庫中發(fā)布庫),您不會遇到同樣的問題.
在這種情況下,gradle 使用 pom 文件下載依賴項,該文件將包含依賴項列表.
You should use a maven repository (you have to publish the library in a private or public maven repo), you will not have the same issue.
In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list.
這篇關(guān)于本地 aar 庫的傳遞依賴的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!