为什么我在本机反应中遇到此错误?

时间:2018-10-08 06:03:10

标签: react-native

我是新来的本地人。当我运行react-native run-android时,出现此错误。

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\Stay Hungry\app developement\Aarogya\node_modules\react-native-share\android\build.gradle' line: 53

* What went wrong:
A problem occurred evaluating project ':react-native-share'.
> Could not find method compileOnly() for arguments [com.facebook.react:react-native:+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 7 mins 24.686 secs
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/getting-started.html

我跟踪到错误位置的路径,并且我的build.gradle在下面:

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }

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

apply plugin: 'com.android.library'

def safeExtGet(prop, fallback) {
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

android {
    compileSdkVersion safeExtGet('compileSdkVersion', 27)
    buildToolsVersion safeExtGet('buildToolsVersion', '27.0.3')


    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', 16)
        targetSdkVersion safeExtGet('targetSdkVersion', 27)

        versionCode 1
        versionName "1.0.0"
    }
    lintOptions {
        abortOnError false
        warning 'InvalidPackage'
    }
}

repositories {
    mavenCentral()
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
    jcenter()
}

dependencies {
    compileOnly "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
    implementation "com.android.support:appcompat-v7:${safeExtGet('supportLibVersion', '27.1.0')}"
}

我不知道这里出了什么问题。我什至还没有开始在app.js中编写代码。我正在使用物理设备通过adb设备运行代码。

1 个答案:

答案 0 :(得分:0)

您收到的错误来自库react-native-share。

您是否按照说明正确安装了它?