React Native无法找到com.android.tools.build:gradle:3.4.2

时间:2019-10-18 12:33:13

标签: android reactjs react-native gradle

我是React native的新手,它试图开始一个新项目。我关注了google docs,并且已经安装了android studio。如文档中所述,在环境变量中添加了ANROID_HOME,在系统变量中添加了平台工具。在运行react-native run-android时。我收到此错误

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'AwesomeProject'.

> Could not resolve all artifacts for configuration ':classpath'.
   > Could not find com.android.tools.build:gradle:3.4.2.

我的android studio versin插件是3.4.2,这是我的build.gradle文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.4.2")

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

和我的gradle-wrapper.properties文件

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

1 个答案:

答案 0 :(得分:1)

感谢所有答案,我想在这里提供答案供其他人使用。

我的问题是由于gradle和android studi插件的版本冲突。

1-打开android studio并开始一个新项目
2-应该有一个builde.gradle和gradle包装器文件
3-您在此处看到的用于例如5.1.1或更高版本的gradle版本是您必须在项目中使用的版本**
4-将项目build.gradle文件中的类路径com.android.tools.build:gradle:更改为3.4.2

5-将gradle包装器属性分发路径更改为distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip