React Native工程在運(yùn)行Android的時(shí)候會(huì)下載gradle,但是由于眾所周知的問(wèn)題,總是下載失敗,這時(shí)可以通過(guò)修改 <APP_ROOT>/android/wrapper/gradle-wrapper.properties 文件中 distributionUrl 參數(shù)使用國(guó)內(nèi) gradle 鏡像來(lái)提高下載速度。
下面是國(guó)內(nèi)的兩個(gè)鏡像,可以找到自己需要的gradle版本,然后替換 <APP_ROOT>/android/wrapper/gradle-wrapper.properties 文件中 distributionUrl 參數(shù)。
- 阿里云鏡像:https://mirrors.aliyun.com/macports/distfiles/gradle/
- 騰訊云鏡像:https://mirrors.cloud.tencent.com/gradle/
比如,下面是我工程下 <APP_ROOT>/android/wrapper/gradle-wrapper.properties 文件原內(nèi)容
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
修改后內(nèi)容
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.6-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
然后重新運(yùn)行 npm start。