前文回复
flutter环境配置
链接
背景
有了前文回顾,但是发现有部分的电脑,还是在下载环境的过程中,会卡在gradle builde的情况。所以有了该文章。
原因
配置了fullter的镜像,但是默认使用安卓的gradle变量,还是有可能会有问题的。这里除了配置安卓的项目级别列表的gradle镜像以外。还要在gradle的目录配置默认的访问资源路径。
通用的配置,项目build.gradle核心配置如下:
maven { url 'https://maven.aliyun.com/repository/google' }maven { url 'https://maven.aliyun.com/repository/central' }maven { url 'https://maven.aliyun.com/repository/public' }maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
上述配置已经是司空见惯了,不再啰嗦。
下面介绍一种方法,看看能否解决你遇到卡再gradle build的问题。
(1)找到你项目所用gradle所在的目录
(2)新建一个init.gradle放到根目录
内容如下:
allprojects{repositories {def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/central/'def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/public/'all { ArtifactRepository repo ->if(repo instanceof MavenArtifactRepository){def url = repo.url.toString()if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('http://repo1.maven.org/maven2')) {project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."remove repo}if (url.startsWith('https://jcenter.bintray.com/') || url.startsWith('http://jcenter.bintray.com/')) {project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."remove repo}}}maven {url ALIYUN_REPOSITORY_URLurl ALIYUN_JCENTER_URLurl 'https://maven.aliyun.com/repository/google/'url 'https://maven.aliyun.com/repository/gradle-plugin/'}}buildscript{repositories {def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/central/'def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/public/'all { ArtifactRepository repo ->if(repo instanceof MavenArtifactRepository){def url = repo.url.toString()if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('http://repo1.maven.org/maven2')) {project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."remove repo}if (url.startsWith('https://jcenter.bintray.com/') || url.startsWith('http://jcenter.bintray.com/')) {project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."remove repo}}}maven {url ALIYUN_REPOSITORY_URLurl ALIYUN_JCENTER_URLurl 'https://maven.aliyun.com/repository/google/'url 'https://maven.aliyun.com/repository/gradle-plugin/'}}}
}
然后重新运动项目的builde,看看能否成功。
本文只是仅仅记录众多原因中的一种,并不一定能解决全部问题。
that’s all----------------------------------------------------------------------