1、aar包导入项目中
网上很多教程都是现将arr包导入到libs目录中,在app目录下的build.grade文件中添加
repositories {
flatDir {
dirs 'libs'
}
}
但是我尝试了之后还是会编译报错build was configured to prefer settings repositories over project repositories but repository ‘flatdir’ was added by build file,最终发现是新版本的grade将repositories放到了setting.grade文件中,所以我们应该这样添加
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
flatDir {
dirs 'libs'
}
}
}
rootProject.name = "DftcLauncher"
include ':app'
最后在build.grade文件中添加上依赖
implementation(name:'xxx',ext:'aar')
implementation fileTree(dir: 'libs',includes: ['*.jar'])
我的gradle的版本是7.0.2。