android - 安装 React Navigation 和手势处理程序后出错

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

我是 react-native 的新手,正在尝试在适用于 Windows 的 Android Studio 中使用 react native 构建 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是什么。

如有任何帮助,我们将不胜感激!

最佳答案

已知问题(参见:bug with react-native link in android and windows),希望能尽快修复。

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

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

...与...

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

关于android - 安装 React Navigation 和手势处理程序后出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54790788/

相关文章:

android - AsyncTask 第一次执行时花费太多时间

android - 如何获取日期、小时、分钟以达到特定日期

android - 我如何在android中将对象从一个应用程序发送到另一个应用程序

javascript - React Native - FlatList 排序而不排序数据

android - 使用 gradle 为构建变体创建 Activity 别名

android-gradle-plugin - 合并 Android 单元测试和连接测试代码覆盖率数据已损坏

android - 以编程方式将我的应用程序添加到android中的AutoStart应用程序列表

ios - React Native - 当键盘显示时调整 ScrollView (ios)

firebase - 如何选择一个数组到文档 firestore 中?

android - 无法解析 : junit:junit:4. 12