React Native(Android)-无法转换hermes-debug.aar

balp4ylt  于 2023-05-15  发布在  Android
关注(0)|答案(4)|浏览(274)

我正在使用一个旧的React Native应用程序,并希望将RN版本从版本^0.64.2升级到0.70.1。使用npx react-native upgrade命令后,依赖项的版本号发生了变化。我还编辑了andriod\app文件夹中的build.gradle,如下面的document所示:

project.ext.react = [
    enableHermes: true  // clean and rebuild if changing
]
...
dependencies {
    ...
    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
    ...
}

然后,我在android文件夹中运行命令./gradlew clean并运行npx react-native run-android。然后出现此错误:

BUILD FAILED in 9s

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.bat 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 hermes-debug.aar to match attributes {artifactType=android-aar-metadata}.
      > Execution failed for JetifyTransform: D:\{ProjectFolder}\node_modules\hermes-engine\android\hermes-debug.aar.
         > Transform's input file does not exist: D:\{ProjectFolder}\node_modules\hermes-engine\android\hermes-debug.aar. (See https://issuetracker.google.com/issues/158753935)

花了一段时间后,我还发现,有没有hermes-engine文件夹内node_modules文件夹,但仍然没有线索该怎么办。
这是我的包。json:

{
  "name": "MyApp",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@notifee/react-native": "^3.0.4",
    "@react-native-async-storage/async-storage": "^1.17.10",
    "@react-native-community/art": "^1.2.0",
    "@react-native-community/datetimepicker": "^3.5.2",
    "@react-native-firebase/app": "^12.9.0",
    "@react-native-firebase/messaging": "^12.9.0",
    "@react-navigation/material-top-tabs": "^6.2.1",
    "@react-navigation/native": "^6.0.1",
    "@react-navigation/stack": "^6.2.1",
    "axios": "^0.24.0",
    "fbjs": "^3.0.4",
    "jest": "^26.6.3",
    "jwt-decode": "^3.1.2",
    "moment": "^2.29.3",
    "moment-timezone": "^0.5.34",
    "prop-types": "^15.8.1",
    "react": "18.1.0",
    "react-native": "0.70.1",
    "react-native-biometrics": "^2.1.4",
    "react-native-camera": "^3.35.0",
    "react-native-chart-kit": "^6.12.0",
    "react-native-elements": "^2.0.4",
    "react-native-file-viewer": "^2.1.1",
    "react-native-fs": "^2.20.0",
    "react-native-gesture-handler": "^1.10.3",
    "react-native-image-crop-picker": "^0.32.2",
    "react-native-modal": "^11.5.6",
    "react-native-pager-view": "^5.4.24",
    "react-native-pdf": "^6.2.0",
    "react-native-picker-select": "^8.0.0",
    "react-native-pie-chart": "^2.0.2",
    "react-native-render-html": "^6.3.4",
    "react-native-safe-area-context": "^3.0.2",
    "react-native-screens": "^3.13.1",
    "react-native-simple-toast": "^1.1.2",
    "react-native-svg": "^12.1.1",
    "react-native-swipe-list-view": "^3.2.9",
    "react-native-tab-view": "^3.1.1",
    "react-native-vector-icons": "^7.0.0",
    "react-navigation": "^4.4.0",
    "react-query": "^3.34.2",
    "react-redux": "^7.2.0",
    "redux": "^4.0.5",
    "redux-devtools-extension": "^2.13.8",
    "redux-thunk": "^2.3.0",
    "toggle-switch-react-native": "^3.3.0"
  },
  "devDependencies": {
    "@react-native-community/eslint-config": "^2.0.0",
    "babel-plugin-root-import": "^6.5.0",
    "eslint": "^7.14.0",
    "react-test-renderer": "^17.0.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

更新:编辑package.json,使用npm install添加hermes-engine后,仍然出现错误。以下是错误:

npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: react-query@3.34.2
npm ERR! Found: react@18.1.0
npm ERR! node_modules/react
npm ERR!   react@"18.1.0" from the root project
npm ERR!   peer react@"*" from @jsamr/react-native-li@2.3.1
npm ERR!   node_modules/@jsamr/react-native-li
npm ERR!     @jsamr/react-native-li@"^2.3.0" from react-native-render-html@6.3.4
npm ERR!     node_modules/react-native-render-html
npm ERR!       react-native-render-html@"^6.3.4" from the root project
npm ERR!   27 more (@react-native-community/art, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.0 || ^17.0.0" from react-query@3.34.2
npm ERR! node_modules/react-query
npm ERR!   react-query@"^3.34.2" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: react@17.0.2
npm ERR! node_modules/react
npm ERR!   peer react@"^16.8.0 || ^17.0.0" from react-query@3.34.2
npm ERR!   node_modules/react-query
npm ERR!     react-query@"^3.34.2" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
zf9nrax1

zf9nrax11#

我也在升级RN版本到0.70.1,从0.69.x你有一些关于爱马仕的app/build.gradle的变化。

...

if (enableHermes) {
    implementation("com.facebook.react:hermes-engine:+") {
        exclude group: 'com.facebook.fbjni'
    }
} else {
    implementation jscFlavor
}
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermesrelease.aar")

...
来源:Bundled Hermes Documentation

eivgtgni

eivgtgni2#

尝试使用--legacy-peer-deps选项将其添加到您的package.json和npm安装中:

"dependencies": {
    "hermes-engine": "^0.11.0",
  },
rdlzhqv9

rdlzhqv93#

我经历了同样的错误,并遵循@fernando-garcía建议的解决方案,但对我来说,这还不够。事实上,我犯了一个错误:

TypeError: Cannot read property 'isBatchingLegacy' of undefined, js engine: hermes

这个问题肯定是由于爱马仕造成的,但是我必须调整一些其他的东西来正确更新我的react-native应用程序,让它在react-native 0.70.0下工作。
下面是我正确更新React-Native应用程序以解决问题的步骤:
1.在android/app/build.gradle中添加以下代码段:

dependencies {
    ...
    if (enableHermes) {
        //noinspection GradleDynamicVersion
        implementation("com.facebook.react:hermes-engine:+") {
            exclude group:'com.facebook.fbjni'
        }
    }
}

if (isNewArchitectureEnabled()) {
    // If new architecture is enabled, we let you build RN from source
    // Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
    // This will be applied to all the imported transtitive dependency.
    configurations.all {
        resolutionStrategy.dependencySubstitution {
            substitute(module("com.facebook.react:react-native"))
                    .using(project(":ReactAndroid"))
                    .because("On New Architecture we're building React Native from source")
            substitute(module("com.facebook.react:hermes-engine"))
                    .using(project(":ReactAndroid:hermes-engine"))
                    .because("On New Architecture we're building Hermes from source")
        }
    }
}

1.在android/settings.gradle中添加以下内容:

if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true") {
    include(":ReactAndroid")
    project(":ReactAndroid").projectDir = file('../node_modules/react-native/ReactAndroid')
    include(":ReactAndroid:hermes-engine")
    project(":ReactAndroid:hermes-engine").projectDir = file('../node_modules/react-native/ReactAndroid/hermes-engine')
}

1.更新package.json中的react依赖项(我有17.0.2,我必须更新到18.1.10):

dependencies {
    ...
    "react": "18.1.0"
}
col17t5w

col17t5w4#

我也对这个问题很感兴趣,同样的事情也发生在我身上,我已经检查了升级助手,我正在从0.68.5升级到0.70.1。
我还没有打开NEW_ARCHITECTURE标志。
安装hermes-engine软件包似乎不是一个好的解决方案,因为升级步骤没有提到应该这样做。

相关问题