我负责维护使用React Native开发的应用程序两年。安卓项目的目标设置为API 30,客户端希望将其更新为API 31。我原以为在格雷德尔很容易改变的事情,结果却让人头疼。
我不知道我已经尝试了多少东西(更新react native、更新gradle、安装JDK11…(,但我最终放弃了更改,并再次从存储库中克隆了所有代码。
以下是我现在确定已经完成的步骤:
- 安装JDK11(以前已安装(
- 从存储库中克隆React Native项目
- 运行命令
npm install
- 将Gradle更新到7.3.3版本(我通过使用Android Studio打开Android项目来完成这一操作(
这些是packages.json:中包的版本
"dependencies": {
...
"react": "17.0.2",
"react-native": "0.67.2",
...
},
"devDependencies": {
"@babel/core": "7.12.13",
"@babel/runtime": "7.12.13",
"@react-native-community/eslint-config": "1.1.0",
"babel-jest": "25.5.1",
"eslint": "6.8.0",
"jest": "25.5.4",
"metro-react-native-babel-preset": "0.59.0",
"react-test-renderer": "16.13.1"
},
此时,我可以使用react-native run-android
命令运行应用程序,但不加载图像。当然,由于我已经从头开始克隆了这个项目,所以我必须创建资源。为此,我执行了这个命令,我在过去使用过很多次:
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/ app/src/main/res
但我得到了这个错误:
warn Package react-native-vector-icons contains invalid configuration: "dependency.assets" is not allowed. Please verify it's properly linked using "react-native config" command and contact the package maintainers about this.
Welcome to Metro v0.72.3
Fast - Scalable - Integrated
error Unable to resolve module C:Users{myusername}AppDataRoamingnpmnode_modulesreact-nativenode_modulesmetro-runtimesrcmodulesempty-module.js from C:DATAProjectsiDOLCode{myappname}_:
None of these files exist:
* ..........Users{myusername}AppDataRoamingnpmnode_modulesreact-nativenode_modulesmetro-runtimesrcmodulesempty-module.js(.native|.native.js|.js|.native.jsx|.jsx|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
* ..........Users{myusername}AppDataRoamingnpmnode_modulesreact-nativenode_modulesmetro-runtimesrcmodulesempty-module.jsindex(.native|.native.js|.js|.native.jsx|.jsx|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx).
Error: Unable to resolve module C:Users{myusername}AppDataRoamingnpmnode_modulesreact-nativenode_modulesmetro-runtimesrcmodulesempty-module.js from C:DATAProjectsiDOLCode{myappname}_:
None of these files exist:
* ..........Users{myusername}AppDataRoamingnpmnode_modulesreact-nativenode_modulesmetro-runtimesrcmodulesempty-module.js(.native|.native.js|.js|.native.jsx|.jsx|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
* ..........Users{myusername}AppDataRoamingnpmnode_modulesreact-nativenode_modulesmetro-runtimesrcmodulesempty-module.jsindex(.native|.native.js|.js|.native.jsx|.jsx|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
at ModuleResolver.resolveDependency (C:Users{myusername}AppDataRoamingnpmnode_modulesreact-nativenode_modulesmetrosrcnode-hasteDependencyGraphModuleResolution.js:152:15)
at ModuleResolver._getEmptyModule (C:Users{myusername}AppDataRoamingnpmnode_modulesreact-nativenode_modulesmetrosrcnode-hasteDependencyGraphModuleResolution.js:50:26)
at ModuleResolver._getFileResolvedModule (C:Users{myusername}AppDataRoamingnpmnode_modulesreact-nativenode_modulesmetrosrcnode-hasteDependencyGraphModuleResolution.js:219:21)
at ModuleResolver.resolveDependency (C:Users{myusername}AppDataRoamingnpmnode_modulesreact-nativenode_modulesmetrosrcnode-hasteDependencyGraphModuleResolution.js:148:19)
at DependencyGraph.resolveDependency (C:Users{myusername}AppDataRoamingnpmnode_modulesreact-nativenode_modulesmetrosrcnode-hasteDependencyGraph.js:264:43)
at Object.resolve (C:Users{myusername}AppDataRoamingnpmnode_modulesreact-nativenode_modulesmetrosrclibtransformHelpers.js:170:21)
at resolveDependencies (C:Users{myusername}AppDataRoamingnpmnode_modulesreact-nativenode_modulesmetrosrcDeltaBundlergraphOperations.js:466:33)
at processModule (C:Users{myusername}AppDataRoamingnpmnode_modulesreact-nativenode_modulesmetrosrcDeltaBundlergraphOperations.js:232:31)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
info Run CLI with --verbose flag for more details.
有一件事我不明白:安装的react本机版本是"0.67.2〃;,但是当我试图创建资源时;欢迎使用Metro v0.72.3";。我不知道这是否有道理。
文件C:Users{myusername}AppDataRoamingnpmnode_modulesreact-nativenode_modulesmetro-runtimesrcmodulesempty-module.js
退出。
你知道我为什么会犯这个错误吗?
cli似乎已损坏。我用--force
:解决了安装它的问题
npm install -g react-native-cli @react-native-community/cli --force