AndroidStudio2022.3.1 Patch3使用国内下载源加速

记录一下这个版本的as在使用国内下载源加速碰到的诸多问题。

一、gradle-8.0-bin.zip下载慢

编辑项目文件夹/gradle/wrapper/gradle-wrapper.properties,文件内容改为如下:

sql 复制代码
#Fri Nov 24 18:50:06 CST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://mirrors.aliyun.com/macports/distfiles/gradle/gradle-8.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

点击同步即可。

二、使用阿里云加速报错(kts版本)

先看看以前的加速配置(settings.gradle):

pluginManagement {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/public' }
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/public' }
    }
}
rootProject.name = "p2v"
include ':app'

再来看看settings.gradle.kts的默认配置:

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.name = "My Application"
include(":app")

好像也相差没多少,拷贝核心代码过去试试,改后文件如下:

pluginManagement {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/public' }
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/public' }
    }
}

rootProject.name = "My Application"
include(":app")

开始同步...

接着肯定会提示:settings.gradle.kts:3:21: Unexpected tokens (use ';' to separate expressions on the same line)

哦哦哦,kts的语法和gls不一样,再进行如下修改:

sql 复制代码
pluginManagement {
    repositories {
        maven { url=uri("https://maven.aliyun.com/repository/central") }
        maven { url=uri("https://maven.aliyun.com/repository/google") }
        maven { url=uri("https://maven.aliyun.com/repository/gradle-plugin") }
        maven { url=uri("https://maven.aliyun.com/repository/jcenter") }
        maven { url=uri("https://maven.aliyun.com/repository/public") }
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        maven { url=uri("https://maven.aliyun.com/repository/central") }
        maven { url=uri("https://maven.aliyun.com/repository/google") }
        maven { url=uri("https://maven.aliyun.com/repository/gradle-plugin") }
        maven { url=uri("https://maven.aliyun.com/repository/jcenter") }
        maven { url=uri("https://maven.aliyun.com/repository/public") }
    }
}

rootProject.name = "My Application"
include(":app")

再次点击同步.....

再次报出错误:Plugin [id: 'com.android.application', version: '8.1.3', apply: false] was not found in any of the following sources

eem.....大概意思是找不到相关的依赖库,上阿里云仓库查询了一下,是有这个com.android.application 8.1.3 库的,那是什么原因呢?

再往下翻翻错误日志,找到核心错误:Plugin Repositories (could not resolve plugin artifact 'com.android.application:com.android.application.gradle.plugin:8.1.3')

再次然上阿里云仓库查询了一下,是有com.android.application.gradle.plugin这个库的,但是没有8.1.3版本(as里的默认使用的版本),于是改成阿里云仓库里有的版本,编辑项目文件夹/build.gradle.kts,改完文件内容如下:

sql 复制代码
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id("com.android.application") version "8.0.1" apply false
    id("org.jetbrains.kotlin.android") version "1.9.0" apply false
}

再次点击同步....

可以看到依赖库都开始在愉快的下载了....

你以为这就完了?

然后还会下载一个叫做gradle-8.0-src.zip的文件,40M左右,但下载速度非常慢只有十几kb,万幸的是它只会在第一次下载,以后就都不会了,这里就不特意去做加速了(当然也是可以的,我的第一想法是搭建本地服务器来代理文件的下载)。

相关推荐
Winston Wood2 小时前
Android Parcelable和Serializable的区别与联系
android·序列化
清风徐来辽2 小时前
Android 项目模型配置管理
android
帅得不敢出门2 小时前
Gradle命令编译Android Studio工程项目并签名
android·ide·android studio·gradlew
problc3 小时前
Flutter中文字体设置指南:打造个性化的应用体验
android·javascript·flutter
帅得不敢出门13 小时前
安卓设备adb执行AT指令控制电话卡
android·adb·sim卡·at指令·电话卡
我又来搬代码了15 小时前
【Android】使用productFlavors构建多个变体
android
德育处主任17 小时前
Mac和安卓手机互传文件(ADB)
android·macos
芦半山17 小时前
Android“引用们”的底层原理
android·java
迃-幵17 小时前
力扣:225 用队列实现栈
android·javascript·leetcode
大风起兮云飞扬丶18 小时前
Android——从相机/相册获取图片
android