Android Studio运行kotlin项目,一直Read timed out
下载别人的Kotlin项目,导入as后,运行app一直失败,提示Read timed out,有2种解决办法
第一种方式:gradle.properties
修改kotlin项目种的gradle.properties文件
systemProp.http.keepAlive=true
systemProp.http.keepAliveDuration=600000
第二种方式:使用aliyun maven(gradle7.0+)
修改settings.gradle文件
pluginManagement {repositories {gradlePluginPortal()google()mavenCentral()}
}
dependencyResolutionManagement {repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories {maven {allowInsecureProtocol = trueurl 'http://maven.aliyun.com/nexus/content/groups/public/'}maven {allowInsecureProtocol = trueurl 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}maven {allowInsecureProtocol = trueurl 'http://maven.aliyun.com/nexus/content/repositories/google'}maven {allowInsecureProtocol = trueurl 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin'}google()mavenCentral()maven { url 'https://jitpack.io' }}
}
rootProject.name = "Shlla"
include ':app'
修改项目目录中的build.gradle文件
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {repositories {maven {allowInsecureProtocol = trueurl 'http://maven.aliyun.com/nexus/content/groups/public/'}google()mavenCentral()}dependencies {// 这里指定的是grade的版本,与你自己grade版本对上就可以了// 太无语了,其实咱们就根据下面plugins中的版本一样 就可以了// 不用跟自己的grade保持一致,要低一点,也没关系,反正我是比自己的grade低,下面有图,咱们可以改成跟自己的grade一致,试试看classpath 'com.android.tools.build:gradle:7.3.1'// NOTE: Do not place your application dependencies here; they belong// in the individual module build.gradle files}
}
plugins {id 'com.android.application' version '7.3.1' apply falseid 'com.android.library' version '7.3.1' apply falseid 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}
task clean(type: Delete) {delete rootProject.buildDir
}
依赖还是在app目录下的build.gradle中增加与修改。
参考
2022 最新 Android studio添加阿里云Aliyun Maven仓库
在 build.gradle.kts 添加 maven 仓库
Android Studio : Read timed out和connect timed out的解决方法