Solution to the slow downloading of dependencies when creating a new project in Android Studio 2022
origin
When creating a new Android Studio project, some dependencies are often downloaded slowly due to network problems, among which gradle and kotlin slow down the progress the most.
solution
Solution to slow gradle download
Just change the distributionUrl property of the gradle-wrapper.properties file, as shown below:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
#更换为国内源
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.4-rc-3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
The distributionUrl attribute is changed to domestic source, and you can find the resource link of the corresponding version from Tencent Cloud .
One thing to note is that resources need to be downloaded ending in all, otherwise other dependencies of gradle will still be downloaded from abroad after the change, resulting in slow progress. Please refer to
the corresponding relationship between the third-party source address and the Alibaba source address .
Kotlin dependency download slow solution
Just add two sources to settings.gradle.kts, as shown below:
The code configuration is as follows:
pluginManagement {
repositories {
maven { url=uri("https://maven.aliyun.com/repository/google") }
maven { url=uri("https://maven.aliyun.com/repository/public") }
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
maven { url=uri("https://maven.aliyun.com/repository/google") }
maven { url=uri("https://maven.aliyun.com/repository/public") }
google()
mavenCentral()
}
}
It should be noted that the syntax for introducing third-party sources may change. The old syntax is no longer supported. Please refer to here . Maybe the grammar will change in the future, and readers will need to make adjustments by themselves.
end
After completing the above changes, click Sync Now or Try Again on the project, and you're done.