React Native:尝试在Android上运行时评估项目':app'时发生问题

时间:2018-11-29 10:24:43

标签: android react-native

我有一个React Native应用,当我尝试在我的android设备上运行它时,出现以下错误:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/myname/Desktop/myapp/android/app/build.gradle' line: 1

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
   > java.nio.file.AccessDeniedException: /Users/myname/.android/build-cache.lock

我正在使用以下版本:

  • 本机反应:0.57.3
  • Android Studio:3.2.1
  • java:“ 1.8.0_191”
  • distributionUrl = https://services.gradle.org/distributions/gradle-4.4-all.zip
  • macOS:Mojave 10.14.1

我试图更改Gradle版本,但没有成功。这是我的app/build.gradle

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

buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
    }
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        google()
    }
}
task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
    distributionUrl = distributionUrl.replace("bin", "all")
}

1 个答案:

答案 0 :(得分:5)

1。将gradle升级到:-

buildscript {
dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
}

2。删除gradle缓存文件。对于Windows用户,它可以位于C:\ Users \ username.gradle \ caches之类的路径中。对于像sys这样的Unix,它将是〜.gradle \ caches