咸鱼

咸鱼是以盐腌渍后,晒干的鱼

0%

Android Studio Arctic Fox 版本升级补丁

升级了Android Studio创建了一个新的新项目,添加aar库出现各种找不到库的问题。
版本信息如下:

1
2
3
4
5
6
Android Studio Arctic Fox | 2020.3.1
Build #AI-203.7717.56.2031.7583922, built on July 27, 2021
Runtime version: 11.0.10+0-b96-7249189 amd64
VM: OpenJDK 64-Bit Server VM by Oracle Corporation
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation

下面记录一下变动:

  1. repositories变动
    /project/build.gradle 内的 allprojects 节点移动到了 /project/settings.gradle,内容如下:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
    google()
    mavenCentral()
    jcenter() // Warning: this repository is going to shut down soon
    flatDir {
    dirs 'libs'
    }
    }
    }
  2. 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'