Paw*_* S. 11 android upgrade react-native
我正在开发一个旧的 React Native 应用程序,想要将 RN 版本从版本 ^0.64.2 升级到 0.70.1。使用命令后npx react-native upgrade,依赖项的版本号发生了变化。我还按照本文档build.gradle中的说明在文件夹中进行编辑:andriod\app
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
}
...
}
Run Code Online (Sandbox Code Playgroud)
之后,我./gradlew clean在 android 文件夹中运行命令并运行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)
Run Code Online (Sandbox Code Playgroud)
hermes-engine花了一段时间后,我还发现文件夹内没有文件node_modules夹,但仍然不知道该怎么办。
这是我的 package.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"
}
}
Run Code Online (Sandbox Code Playgroud)
更新npm install:我编辑 package.json 并使用add后仍然出现错误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.
Run Code Online (Sandbox Code Playgroud)
小智 18
我还将 RN 版本升级到 0.70.1,从 0.69.x 开始,您需要对 Hermes 进行一些更改app/build.gradle。
...
if (enableHermes) {
implementation("com.facebook.react:hermes-engine:+") {
exclude group: 'com.facebook.fbjni'
}
} else {
implementation jscFlavor
}
Run Code Online (Sandbox Code Playgroud)
def hermesPath = "../../node_modules/hermes-engine/android/";
Run Code Online (Sandbox Code Playgroud)
debugImplementation files(hermesPath + "hermes-debug.aar")
Run Code Online (Sandbox Code Playgroud)
releaseImplementation files(hermesPath + "hermesrelease.aar")
Run Code Online (Sandbox Code Playgroud)
...
来源:Hermes 捆绑文档
尝试将其添加到您的 package.json 并使用 --legacy-peer-deps 选项再次 npm install :
"dependencies": {
"hermes-engine": "^0.11.0",
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9740 次 |
| 最近记录: |