【问题标题】:Issue with making react native run使反应本机运行的问题
【发布时间】:2017-10-11 07:58:49
【问题描述】:

要安装的信息源: - https://facebook.github.io/react-native/docs/getting-started.html

另外,我添加了环境变量。

然后使用这些命令,完美运行:

npm 开始 npm 运行安卓

然后当我运行这个命令时:

react-native run-android

它显示了这个errorImage showing error stack

D:\Projects\React-Native\AwesomeProject>react-native run-android
    Scanning 768 folders for symlinks in D:\Projects\React-Native\AwesomeProject\nod
    e_modules (31ms)
    Starting JS server...
    Building and installing the app on the device (cd android && gradlew.bat install
    Debug)...

    FAILURE: Build failed with an exception.

    * Where:
    Build file 'D:\Projects\React-Native\AwesomeProject\android\app\build.gradle' li
    ne: 1

    * What went wrong:
    A problem occurred evaluating project ':app'.
    > java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : U
    nsupported major.minor version 52.0

    * 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: 3.124 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/android-setup.html
    events.js:182
          throw er; // Unhandled 'error' event
          ^

    Error: spawn cmd.exe ENOENT
        at _errnoException (util.js:1019:11)
        at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
        at onErrorNT (internal/child_process.js:374:16)
        at _combinedTickCallback (internal/process/next_tick.js:138:11)
        at process._tickCallback (internal/process/next_tick.js:180:9)

构建 gradle

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

            // 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"
            }
        }
    }

【问题讨论】:

  • 你能分享你的gradle文件吗?那真的很有帮助
  • @HarkiratSaluja 添加了

标签: android react-native installation


【解决方案1】:

显然您的 build.gradle 文件中有错误。

不看文件,我想它可能与最低 android 版本或类似的东西有关。

此 gradle 文件包含构建您的 android 应用程序的所有信息,因此如果它包含错误,您将收到“FAILURE: Build failed with an exception。”

【讨论】:

    【解决方案2】:

    我已经通过添加正确的环境变量路径解决了这个问题。请参考随附的屏幕截图。

    C:\Windows\System32*WindowsPowerShell\v1.0*;
    C:\Users\gyrix**AppData\Roaming\npm**;
    C:\Users\gyrix**AppData\Local\Yarn\bin**;
    D:\Android\sdk1**平台工具**;
    E:\android-sdk**build-tools\25.0.2**;
    D:\Android**sdk1**;
    D:\Android\sdk1**tools**;
    C:\Program Files**Java\jdk1.8.0_144\bin**;

    注意:请以粗体指定文件夹的路径,它可能因系统而异。 enter code here

    【讨论】:

      猜你喜欢
      • 2021-11-29
      • 2019-07-12
      • 2020-03-20
      • 2016-11-10
      • 2022-08-02
      • 2019-10-10
      • 1970-01-01
      • 2021-06-24
      • 2018-04-03
      相关资源
      最近更新 更多