新版AndroidStudio無法直接導入aar問題,AS導入aar報錯解決方案

直接導入.aar文件,新版Androidstudio將會報錯,報錯信息如下????

Execution failed for task ':library_module:bundleDebugAar'.
> Direct local .aar file dependencies are not supported when building an AAR. 
The resulting AAR would be broken because the classes and Android resources from any local .aar 
file dependencies would not be packaged in the resulting AAR. Previous versions of the Android 
Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The 
following direct local .aar file dependencies of the :library_module project caused this error: 
______.aar

我找到了解決方案/解決方法。如果您使用的是 Android Studio 4.2+,則需要手動執(zhí)行添加 .jar/.aar 文件的選項通過對話框執(zhí)行的所有操作:

  1. 打開你的flutter項目的android文件夾作為Android Studio項目
  2. 在 android 根文件夾中創(chuàng)建文件夾 library-ola(命名隨意) 并放置相應的 aar 文件并創(chuàng)建空的 build.gradle 文件,如下面的屏幕截圖所示:


    image.png

當然如果有多個.aar文件可以創(chuàng)建多個文件(eg:library-ola-1,library-ola-2,library-ola-X)

  1. library-ola/build.gradle 文件的內(nèi)容:
configurations.maybeCreate("default")
artifacts.add("default", file('CutSameIF_ck2.6.6_20220714.aar'))
  1. 在 android 根文件夾中找到 settings.gradle 文件,打開它并在文件頂部添加以下行:
include ':library-ola'
//如果創(chuàng)建了多個文件夾,根據(jù)實際情況來配置
include ':library-ola-xx'

6.重新clean和build工程,如果還有別的module有應用到對應的.aar 只需要將 ':library-ola'
在build.gradlew中配置即可

  1. 就這樣!現(xiàn)在重寫構(gòu)建你的應用程序,希望一切順利!
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容