问题:react native初次运行时,gradle加载很慢,导致最后总是启动项目不成功
解决方案:找到 .gradle 的目录,我这里本地是:C:\Users\Administrator.gradle,一般在C盘的用户文件夹下,如果没有的话,运行react native项目后就有了,如果第一次运行就很顺利,那么恭喜你,如果不行的话,请往下看。
在C:\Users\Administrator.gradle目录下新建一个gradle的初始化文件
gradle的代码如下,保存后,再次启动react native就可以了:
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_URL
url ALIYUN_JCENTER_URL
url '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_URL
url ALIYUN_JCENTER_URL
url 'https://maven.aliyun.com/repository/google/'
url 'https://maven.aliyun.com/repository/gradle-plugin/'
}
}
}
}
————————————————
版权声明:本文为CSDN博主「LINGK98」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/LINGK98/article/details/127780115