升级了Android Studio创建了一个新的新项目,添加aar库出现各种找不到库的问题。
版本信息如下:
| 1 | Android Studio Arctic Fox | 2020.3.1 | 
下面记录一下变动:
- repositories变动/project/build.gradle内的allprojects节点移动到了/project/settings.gradle,内容如下:1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11dependencyResolutionManagement { 
 repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
 repositories {
 google()
 mavenCentral()
 jcenter() // Warning: this repository is going to shut down soon
 flatDir {
 dirs 'libs'
 }
 }
 }
- libs目录变动
 从以上flatDir配置看到,’libs’ 就是当前目录下的 libs 目录
 libs目录默认由/project/module/libs改为/project/libs。
 不设置flatDir,项目构建时会提示错误。
1. 旧版完整的代码:
- /project/build.gradle- 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30- buildscript { 
 repositories {
 google()
 mavenCentral()
 maven { url 'https://jitpack.io' }
 }
 dependencies {
 classpath 'com.android.tools.build:gradle:4.2.1'
 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"
 // NOTE: Do not place your application dependencies here; they belong
 // in the individual module build.gradle files
 }
 }
 allprojects {
 repositories {
 google()
 jcenter()
 maven { url 'https://jitpack.io' }
 flatDir{
 dirs 'libs'
 }
 }
 }
 task clean(type: Delete) {
 delete rootProject.buildDir
 }
- /project/settings.gradle- 1 
 2- rootProject.name = "appDemo" 
 include ':app'
2. 新版完整的代码:
- /project/build.gradle- 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19- buildscript { 
 repositories {
 google()
 mavenCentral()
 maven { url 'https://jitpack.io' }
 }
 dependencies {
 classpath "com.android.tools.build:gradle:7.0.0"
 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"
 // NOTE: Do not place your application dependencies here; they belong
 // in the individual module build.gradle files
 }
 }
 task clean(type: Delete) {
 delete rootProject.buildDir
 }
- /project/settings.gradle- 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13- 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 = "appDemo"
 include ':app'