【问题标题】:React Native Could not find com.android.tools.build:gradle:3.4.2React Native 找不到 com.android.tools.build:gradle:3.4.2
【发布时间】:2019-10-18 12:33:13
【问题描述】:

我是 React Native 的新手,正在尝试开始一个新项目。我关注了谷歌文档,并且已经安装了 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 版本插件是 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

【问题讨论】:

标签: android reactjs react-native gradle


【解决方案1】:

感谢大家的回答,我想我会在这里提供答案供其他人使用。

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-11
    • 1970-01-01
    • 1970-01-01
    • 2019-11-22
    • 2021-12-16
    • 2019-05-12
    • 2019-11-06
    • 2019-12-27
    相关资源
    最近更新 更多