在之前的工作代码中没有做任何事情,React Native应用就不能运行了

回答 2 浏览 5067 2022-11-05

我目前正在从事一个react native项目的工作。

它有这些软件包作为依赖项

  "dependencies": {
    "@react-native-async-storage/async-storage": "^1.15.5",
    "@react-native-community/checkbox": "^0.5.8",
    "@react-native-community/cli": "^7.0.3",
    "@react-native-community/clipboard": "^1.5.1",
    "@react-native-community/datetimepicker": "^3.5.2",
    "@react-native-community/masked-view": "^0.1.11",
    "@react-native-picker/picker": "^1.16.3",
    "@react-navigation/drawer": "^5.12.5",
    "@react-navigation/material-top-tabs": "^5.3.15",
    "@react-navigation/native": "^5.9.4",
    "@react-navigation/stack": "^5.14.5",
    "@twotalltotems/react-native-otp-input": "^1.3.11",
    "axios": "^0.21.1",
    "axios-oauth-client": "^1.4.2",
    "axios-token-interceptor": "^0.2.0",
    "moment": "^2.29.1",
    "prop-types": "^15.8.1",
    "react": "17.0.1",
    "react-native": "0.64.1",
    "react-native-animatable": "^1.3.3",
    "react-native-app-intro-slider": "^4.0.4",
    "react-native-calendars": "^1.1264.0",
    "react-native-cardview": "^2.0.5",
    "react-native-date-picker": "^4.2.1",
    "react-native-device-info": "^8.1.3",
    "react-native-eject": "^0.1.2",
    "react-native-geolocation-service": "^5.3.0",
    "react-native-gesture-handler": "^1.10.3",
    "react-native-get-random-values": "^1.8.0",
    "react-native-image-picker": "^4.0.3",
    "react-native-material-dropdown": "^0.11.1",
    "react-native-modal-datetime-picker": "^10.2.0",
    "react-native-modal-picker": "^0.0.16",
    "react-native-pager-view": "^5.4.23",
    "react-native-phone-number-input": "^2.1.0",
    "react-native-picker-select": "^8.0.4",
    "react-native-reanimated": "^2.2.0",
    "react-native-safe-area-context": "^3.2.0",
    "react-native-screens": "^3.3.0",
    "react-native-searchable-dropdown": "^1.1.3",
    "react-native-signature-canvas": "^4.3.0",
    "react-native-simple-toast": "^1.1.4",
    "react-native-slider": "^0.11.0",
    "react-native-step-indicator": "^1.0.3",
    "react-native-tab-view": "^2.16.0",
    "react-native-text-input-mask": "^3.1.4",
    "react-native-vector-icons": "^9.1.0",
    "react-native-webview": "^11.13.0",
    "react-redux": "^7.2.4",
    "uuid": "^8.3.2"
  },

它现在没有运行,没有对以前的工作代码做任何处理,甚至没有在系统中也更新任何东西。

这里是那个错误

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:checkDebugAarMetadata'.

Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Failed to transform react-native-0.71.0-rc.0-debug.aar (com.facebook.react:react-native:0.71.0-rc.0) to match attributes {artifactType=android-aar-metadata, com.android.build.api.attributes.BuildTypeAttr=debug, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}. > Execution failed for JetifyTransform: /Users/username/.gradle/caches/modules-2/files-2.1/com.facebook.react/react-native/0.71.0-rc.0/7a7f5a0af6ebd8eb94f7e5f7495e9d9684b4f543/react-native-0.71.0-rc.0-debug.aar. > Java heap space

  • 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 4s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:checkDebugAarMetadata'.

Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Failed to transform react-native-0.71.0-rc.0-debug.aar (com.facebook.react:react-native:0.71.0-rc.0) to match attributes {artifactType=android-aar-metadata, com.android.build.api.attributes.BuildTypeAttr=debug, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}. > Execution failed for JetifyTransform: /Users/username/.gradle/caches/modules-2/files-2.1/com.facebook.react/react-native/0.71.0-rc.0/7a7f5a0af6ebd8eb94f7e5f7495e9d9684b4f543/react-native-0.71.0-rc.0-debug.aar. > Java heap space

  • 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 4s

at makeError (/Users/username/Desktop/Gitlab/projectname/node_modules/execa/index.js:174:9)
at /Users/username/Desktop/Gitlab/projectname/node_modules/execa/index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (/Users/username/Desktop/Gitlab/projectname/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:5)
at async Command.handleAction (/Users/username/Desktop/Gitlab/projectname/node_modules/@react-native-community/cli/build/index.js:192:9)
Guna 提问于2022-11-05
修复github.com/facebook/react-native/issues/35210中的问题。AliTN 2022-11-05
2 个回答
#1楼 已采纳
得票数 28

在react-native本身有一些问题。

这个问题的解决方案--https://github.com/facebook/react-native/issues/35210

对于react-native ( >= 0.63)

在android/build.gradle中,在allprojects.repositories里面添加这个exclusiveContent。

allprojects {
    repositories {
       exclusiveContent {
           // We get React Native's Android binaries exclusively through npm,
           // from a local Maven repo inside node_modules/react-native/.
           // (The use of exclusiveContent prevents looking elsewhere like Maven Central
           // and potentially getting a wrong version.)
           filter {
               includeGroup "com.facebook.react"
           }
           forRepository {
               maven {
                   url "$rootDir/../node_modules/react-native/android"
               }
           }
       }
        // ...
    }
}

对于较前的react-native (< 0.63)

在你的android/buld.gradle文件的allprojects区域中添加这个内容。

def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())

allprojects {
    configurations.all {
        resolutionStrategy {
            // Remove this override in 0.65+, as a proper fix is included in react-native itself.
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
        }
    }
Guna 提问于2022-11-05
Guna 修改于2022-11-07
在app.gradlew文件中加入了这一点,但仍然无法正常工作。Abdus Sattar Nishad 2022-11-06
#2楼
得票数 3

我也面临这个问题,上次我构建应用程序时,一切正常,但就在昨天,构建开始失败,出现了同样的错误。没有做任何改变或更新。

Ola Fashade Samson 提问于2022-11-05
以下是对该问题的修复。github.com/facebook/react-native/issues/35210Ola Fashade Samson 2022-11-05
标签