我有一個 android 專案,其中包含一個庫 (aar)。Gradle 將解壓檔案并將其存盤在 gradle 快取 (.gradle\caches\transforms-2) 中。我需要一個 gradle 腳本,我可以在其中從該快取中檢索檔案并將其移動到我的專案中。有誰知道如何做到這一點?
運動部件正在作業。我只需要獲得正確的路徑
tasks.register('moveFile', Copy) {
from "${path_to_build_cache}/path/to/folder/file.conf"
into "${project.rootDir.path}/path/to/folder/"
}
編輯
我現在已經嘗試了@tim_yates 發布的解決方案。問題是我現在收到錯誤CustomMessageMissingMethodException: Could not find method from() for arguments [ZIP 'C:\Users\nthemmer\.gradle\caches\modules-2\files-2.1\path\to\aar on task ':my-project:movefiles' of type org.gradle.api.DefaultTask似乎是正確讀取了 aar 檔案,但它不僅有一個檔案。任何幫助表示贊賞:)
編輯
該解決方案發布了我的 tim_yates 為我作業!對我來說仍然有點神奇仍然是我到達那里。再次感謝 :)
uj5u.com熱心網友回復:
您應該能夠使用 Gradle 為您找到它,而不是搜索快取...
下面是一個例子:
configurations {
aar
}
dependencies {
aar('com.mikhaellopez:circularimageview:4.3.0@aar')
}
tasks.register('moveFile', Copy) {
from(zipTree(configurations.aar.singleFile)) {
include "res/values/values.xml"
}
into project.layout.buildDirectory.dir('here')
}
將檔案復制到 ./build/here/res/values/values.xml
編輯
所以可能有多種方法可以做到這一點,但這里是一種。
定義一個配置,我們將用于您想要從中獲取檔案的單個依賴項,并從中compileClasspath擴展(因此依賴項最終會回到之前所在的編譯類路徑中)
configurations {
aar
compileClasspath.extendsFrom aar
}
然后在您參考 aar 的依賴項中,您應該可以使用aar而不是compileClasspath
dependencies {
aar('com.mikhaellopez:circularimageview:4.3.0@aar')
}
然后你可以使用moveFile上面的任務,并且只會有一個檔案
不能 100% 確定您目前擁有什么,因此不確定這如何適合,但它應該為您提供一個很好的方向。
這是在 Gradle 7.2 上運行的完整構建檔案,并使用circularimageviewarr off maven central 作為測驗物件
plugins {
id('java')
}
repositories {
mavenCentral()
}
configurations {
aar
compileClasspath.extendsFrom aar
}
dependencies {
aar('com.mikhaellopez:circularimageview:4.3.0@aar')
}
tasks.register('moveFile', Copy) {
from(zipTree(configurations.aar.singleFile)) {
include "res/values/values.xml"
}
into project.layout.buildDirectory.dir('here')
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/349150.html
標籤:安卓 等级 时髦的 android-gradle 插件
下一篇:添加華為套件時出現“Couldnotfindcom.huawei.hms:location:6.0.0.302”錯誤
