react-native执行run-android报classpath错误,错误信息如下:
$ react-native run-android
Scanning folders for symlinks in /Users/cc/Desktop/ss/node_modules (8ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project 'sxtbdemo2'.
Could not resolve all files for configuration ':classpath'.
Could not find com.android.tools.build:gradle:3.0.1.
Searched in the following locations:
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
如错误信息所提示,classpath下找不到com.android.tools.build:gradle:3.0.1。
其中下载com.android.tools.build:gradle:3.0.1的maven仓库为jcenter。
解决
原因是com.android.tools.build:gradle:3.0.1插件需要到google的maven仓库下载。参考:Migrate to Android Plugin for Gradle 3.0.0
在build.gradle添加google的maven仓库,如下:
buildscript {
repositories {
//新的插件需要在google仓库下载
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}