【问题标题】:react-native can't find gradle wrapper when building the android app构建android应用程序时react-native找不到gradle wrapper
【发布时间】:2021-07-20 12:54:15
【问题描述】:

我正在将 React Native 从 0.61.5 升级到 0.64.2,我在运行 Android 应用时遇到问题。

这是我尝试启动它时得到的输出:

$ react-native run-android --verbose
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
(node:14959) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
Jetifier found 1313 file(s) to forward-jetify. Using 12 workers...
info JS server already running.
info Installing the app...
debug Running command "cd android && ./gradlew installDebug -PreactNativeDevServerPort=8081"

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: spawn ./gradlew ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)

我的 Android 环境已配置,我实际上可以运行 react-native 运行的完全相同的命令,并且它可以正常运行:

$ cd android && ./gradlew installDebug -PreactNativeDevServerPort=8081
<-------------> 0% CONFIGURING [7s]
> root project > Resolve dependencies of :classpath > maven-metadata.xml

(gradle 最终成功完成构建)。

gradlew 的权限似乎没问题:

$ ls -la ./android/gradlew
-rwxr-xr-x  1 mateusz  139652859  5766 20 Jul 13:44 ./android/gradlew

gradle-wrapper.properties 如下所示:

$ cat android/gradle/wrapper/gradle-wrapper.properties 
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

React Native CLI 是最新的:

$ react-native --version
react-native-cli: 2.0.1
react-native: 0.64.2

我发现有几个人有类似的问题,但没有一个人完全相同。

在仍然使用0.61.5main 分支上一切正常。我怀疑这可能只是我没有更新一些配置文件,但是我不知道如何获得一些关于我必须更改的内容的更详细的提示。

有什么想法吗?谢谢!

【问题讨论】:

  • 您是否连接了安卓设备或模拟器?如果你运行adb devices,它会被检测到吗?
  • 是的,我愿意。 adb devices 找到我的 emulator-5554
  • 也许您可以卸载当前的react-native-cli 并重新安装最新的
  • 谢谢 - 我试过了,仍然是同样的问题。我修改了我的问题以包含版本信息
  • 很遗憾听到这个消息,最后一个问题,当您升级项目时,您是使用了npx react-native upgrade 0.64.2 之类的东西还是遵循了[帮助指南] (react-native-community.github.io/upgrade-helper/…)?

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


【解决方案1】:

原来react-native 在错误的目录中寻找gradlew

它在android/myApp 中寻找它,而它应该只是android/

解决此问题的是 react-native.config.js 中的配置更改:

我之前的:

const android = require('@react-native-community/cli-platform-android');

module.exports = {
  platforms: {
    android: {
      linkConfig: android.linkConfig,
      projectConfig: android.projectConfig,
      dependencyConfig: android.dependencyConfig,
    },
  },
  project: {
    android: {
      sourceDir: './android/myApp',
      stringsPath: './src/main/res/values/strings.xml',
      manifestPath: './src/main/AndroidManifest.xml',
      buildGradlePath: './build.gradle',
      settingsGradlePath: '../settings.gradle',
      assetsPath: './src/main/assets',
      mainFilePath: './src/main/java/com/company/myapp/MyApp.java',
    },
  },
};

我现在拥有的(有效):

const android = require('@react-native-community/cli-platform-android');

module.exports = {
  platforms: {
    android: {
      linkConfig: android.linkConfig,
      projectConfig: android.projectConfig,
      dependencyConfig: android.dependencyConfig,
    },
  },
  project: {
    android: {
      sourceDir: './android',
      stringsPath: './myApp/src/main/res/values/strings.xml',
      manifestPath: './myApp/src/main/AndroidManifest.xml',
      buildGradlePath: './build.gradle',
      settingsGradlePath: './settings.gradle',
      assetsPath: './myApp/src/main/assets',
      mainFilePath: './myApp/src/main/java/com/company/myapp/MyApp.java',
    },
  },
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-01
    • 2013-05-14
    • 2020-04-03
    • 1970-01-01
    • 2018-09-18
    • 1970-01-01
    • 2020-12-06
    • 2023-01-30
    相关资源
    最近更新 更多