安装React Navigation和手势处理程序后发生错误

时间:2019-02-20 16:14:04

标签: android react-native android-gradle android-emulator react-navigation

我是React-native的新手,并试图使用Windows版Android Studio中的本地本机构建android应用。安装react-navigation之后,请按照react-navigation文档中的所有步骤操作,运行react-native run-android,然后在命令行中收到此错误:

PS C:\Users\comp\Desktop\work\reactnative\dansapp> react-native run-android
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat installDebug)...

FAILURE: Build failed with an exception.

* Where:
Settings file 'C:\Users\comp\Desktop\work\reactnative\dansapp\android\settings.gradle' line: 3

* What went wrong:
Could not compile settings file 'C:\Users\comp\Desktop\work\reactnative\dansapp\android\settings.gradle'.
> startup failed:
  settings file 'C:\Users\comp\Desktop\work\reactnative\dansapp\android\settings.gradle': 3: unexpected char:
'\' @ line 3, column 133.
     s\react-native-gesture-handler\android')
                                   ^

  1 error


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

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
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

Command failed: gradlew.bat installDebug

Error: Command failed: gradlew.bat installDebug
    at checkExecSyncError (child_process.js:602:13)
    at Object.execFileSync (child_process.js:622:13)
    at runOnAllDevices (C:\Users\comp\Desktop\work\reactnative\dansapp\node_modules\react-native\local-cli\runAndroid\runAndroid.js:299:19)
    at buildAndRun (C:\Users\comp\Desktop\work\reactnative\dansapp\node_modules\react-native\local-cli\runAndroid\runAndroid.js:135:12)
    at isPackagerRunning.then.result (C:\Users\comp\Desktop\work\reactnative\dansapp\node_modules\react-native\local-cli\runAndroid\runAndroid.js:65:12)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)

PS C:\Users\comp\Desktop\work\reactnative\dansapp>

有人知道这个错误是什么以及如何解决?按照以下步骤安装react-navigation之后,似乎会发生这种情况:https://reactnavigation.org/docs/en/getting-started.html

我已经遵循了这些步骤,包括更改mainActivity.java文件。我也不知道gradle是什么。

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:3)

已知的问题(请参阅:bug with react-native link in android and windows),有望很快得到解决。

跳转到 / dansapp / android / 中的settings.gradle文件并替换...

<template>
  <div class="console" v-html="html">
  </div>
</template>

<script>
import AnsiUp from 'ansi_up'

export default {
  name: 'shell',
  props: ['socket'],
  data () {
    return {
      ansi: undefined,
      content: ''
    }
  },
  computed: {
    html () {
      // Ensures we have some semblance of lines
      return this.ansi.ansi_to_html(this.content).replace(/\n/gm, '<br>')
    }
  },
  watch: {
    socket () {
      this.socket.on('data', data => {
        this.content += data
      })
      this.socket.send('ready')
    }
  },
  beforeMount () {
    this.ansi = new AnsiUp()
  },
  updated () {
    // auto-scroll to the bottom when the DOM is updated
    this.$el.scrollTop = this.$el.scrollHeight
  }
}
</script>

<style lang="scss" scoped>
.console {
  font-family: monospace;
  text-align: left;
  background-color: black;
  color: #fff;
  overflow-y: auto;
}
</style>

...与...

project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '..\node_modules\react-native-gesture-handler\android')