Android Studio Arctic Fox 載入 AAR錯誤訊息: Build was configured to prefer settings repositories over project repositories but repository 'flatDir' was added by build file 'app/build.gradle')

想要導入AAR檔案做為Library使用時,在之前Android Studio Arctic Fox之前的版本,有一項必備的步驟是在app/build.gradle加入了下列的語法,讓libs目錄做為存放library的目錄

repositories {
flatDir {
dirs 'libs'
}
}

但是如果是在Arctic Fox的版本,卻會發生以下的錯誤訊息:

A problem occurred evaluating project ':app'.

> Build was configured to prefer settings repositories over project repositories but repository 'flatDir' was added by build file 'app/build.gradle'


解決的方法:

1. 刪除本來的語法
repositories {
flatDir {
dirs 'libs'
}
}

2. dependencies加上
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])


參考資料:


留言

這個網誌中的熱門文章

Android使用Callback做為傳遞資料/通知的方法

如何實作從API抓取資料顯示在列表頁(ListView)上

Mac安裝JDK後仍出現沒有runtime的錯誤 No Java runtime present, requesting install