[英]How to add .aar dependency in library module?
我有一個庫模塊的.aar
文件。
我想將它用作我其他項目的庫模塊中的庫或依賴項。
我該怎么做?
我嘗試了以下鏈接提供的選項:
http://kevinpelgrims.com/blog/2014/05/18/reference-a-local-aar-in-your-android-project/
僅當我在項目的應用程序模塊中添加.aar
引用時,它才有效。 但不能在庫模塊中工作。
謝謝。
按照此設置,您可以將.aar
依賴項添加到庫模塊
build.gradle(項目:....)
allprojects {
repositories {
jcenter()
mavenCentral()
flatDir {
dirs 'libs'
dirs project(':library_module').file('libs')
}
}
}
build.gradle(模塊:app)
dependencies {
...
compile project(':library_module')
}
build.gradle(Module:library_module)
dependencies {
...
compile(name:'aar_file_name', ext:'aar')
}
settings.gradle(項目設置)
include ':app', ':library_module'
在你需要,你必須在你添加AAR文件中的所有模塊(庫或應用程序) build.gradle
庫:
repositories {
flatDir {
dirs 'libs'
}
}
並添加依賴項:
dependencies {
compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
}
您可以使用頂級文件添加存儲庫,但不能在頂級文件中添加依賴項。
請注意您在模塊中使用的libs文件夾的相對路徑。
我做的有點不同於其他人在這里發布的...
我的主要目標是創建一個庫模塊,其中包含我需要的所有jar和aar。 我的主項目將依賴於這個庫模塊 - 我只想在主項目的build.gradle中使用一行來鏈接這個依賴項。
向項目添加新的庫模塊:文件 - >新建 - >新模塊 - > Android庫
在庫模塊中,打開build.gradle並添加:
// so that the library project can locate the aar in /libs repositories { flatDir { dirs 'libs' } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation fileTree(include: ['*.aar'], dir: 'libs') }
現在您可以將所有jar和aar彈出到庫模塊的/ libs文件夾中。 額外獎勵:無論圖書館名稱無關緊要,都會自動發現
最簡單的方法是將 aar 文件復制到庫模塊的 libs 文件夾中。 並在應用程序級別 build.gradle 實現如下依賴項
implementation files('libs/aar_file_name.aar')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.