【问题标题】:react-native run-android Could not find com.android.tools.build:gradle:3.0.1react-native run-android 找不到 com.android.tools.build:gradle:3.0.1
【发布时间】:2017-11-23 02:32:31
【问题描述】:
apple@mosesdeMacBook-Pro:~/Desktop/sxtbdemo2$ react-native run-android
Scanning folders for symlinks in /Users/apple/Desktop/sxtbdemo2/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
 Required by:
     project :

 Try:
     Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Get more help at https://help.gradle.org

BUILD FAILED in 12s
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have set up your Android development environment: https://facebook.github.io/react-native/docs/android-setup.html

【问题讨论】:

  • 请格式化您的问题
  • 您介意选择已解决的答案吗?谢谢。

标签: android react-native


【解决方案1】:

这通常是您的 gradle 文件中的存储库有问题。

对我来说,像这样修改 build.gradle:

buildscript {
    repositories {
        mavenLocal()
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

所以当你添加 google() 时它应该可以工作。

【讨论】:

  • 已确认。有同样的问题,添加 google() 工作。我相信 google repo 应该在默认设置中。
  • 已确认。重要的是要强调 google() 存储库必须添加到 buildscript.repositories 部分,而不是 allprojects.repositories 部分。
  • 2017-12-14,这个解决方案对我有用! macOS + React Native 0.51 + Android Gradle 4.1
  • 为我工作,拯救了我的一天
  • 像魅力一样工作。
【解决方案2】:
buildscript {
    repositories {
        jcenter()
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'      
    }
}

buildscript() 中添加google() 并同步项目。

参考:https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#apply_plugin

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 1970-01-01
    • 2019-05-11
    • 1970-01-01
    • 2019-02-27
    • 2019-01-05
    • 2018-10-25
    相关资源
    最近更新 更多