配置虚拟机的时候出现 Unable to locate adb,我搜了各种方法,有的说是Android默认的adb端口是5037,跟Windows上进程的端口冲突;有的说sdk没有选中等等等。然而,我挨个试了一下都没有用。直到——
我没有下载下来gradle:
Gradle 原因: Gradle源在国外,国内构建项目的时候经常报错连接超时,修改国内镜像可以解决。
应该搜Android Studio: Gradle/Maven配置国内镜像源
1.打开Android Studio工程文件,找到build.gradle
2.使用文本编辑器打开,默认格式如下:
3.全部注掉,加上
buildscript {repositories {maven {url 'https://maven.aliyun.com/repository/google'}maven {url 'https://maven.aliyun.com/repository/public'}maven {url 'https://maven.aliyun.com/repository/jcenter'}}dependencies {classpath 'com.android.tools.build:gradle:3.5.1'// NOTE: Do not place your application dependencies here; they belong// in the individual module build.gradle files}
}allprojects {repositories {maven {url 'https://maven.aliyun.com/repository/google'}maven {url 'https://maven.aliyun.com/repository/public'}maven {url 'https://maven.aliyun.com/repository/jcenter'}}
}task clean(type: Delete) {delete rootProject.buildDir
}
对所有项目生效
1.打开系统用户的Gradle配置目录:C:\Users\xxx\.gradle
2.新建txt文件
allprojects{repositories {def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/public'def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'all { ArtifactRepository repo ->if (repo instanceof MavenArtifactRepository){def url = repo.url.toString()if (url.startsWith('https://repo1.maven.org/maven2')) {project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."remove repo}if (url.startsWith('https://jcenter.bintray.com/')) {project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."remove repo}}}maven {url ALIYUN_REPOSITORY_URLurl ALIYUN_JCENTER_URL}}
}
3.把文件名改成init.gradle(注意文件后缀名为gradle,如果没有,在任意文件夹里—查看—文件扩展名打开)