React Native 运行报错 error in opening zip file

2022-07-29 09:35:27 浏览数 (1)

基于 React Native 中文网教程 编译并运行 React Native 应用

在项目 (AwesomeProject) 根目录下运行命令 yarn rect-native run-androidyarn android 出现如下错误

代码语言:javascript复制
D:codeAwesomeProject> yarn react-native run-android
PS D:codeAwesomeProject> yarn rect-native run-android
yarn run v1.22.11
error Command "rect-native" not found. Did you mean "react-native"?
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
PS D:codeAwesomeProject> yarn react-native run-android
yarn run v1.22.11
$ D:codeAwesomeProjectnode_modules.binreact-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 870 file(s) to forward-jetify. Using 16 workers...
info Starting JS server...
* daemon not running; starting now at tcp:5037
* daemon started successfully
info Launching emulator...
info Successfully launched emulator.
info Installing the app...
Could not unzip C:Usersw.gradlewrapperdistsgradle-6.9-alldooywd8nv05k16orzxge2b1bsgradle-6.9-all.zip to C:Usersw.gradlewrapperdistsgradle-6.9-alldooywd8nv05k16orzxge2b1bs.
Reason: error in opening zip file
Exception in thread "main" java.util.zip.ZipException: error in opening zip file
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:228)
        at java.util.zip.ZipFile.<init>(ZipFile.java:157)
        at java.util.zip.ZipFile.<init>(ZipFile.java:171)
        at org.gradle.wrapper.Install.unzip(Install.java:239)
        at org.gradle.wrapper.Install.access$900(Install.java:27)
        at org.gradle.wrapper.Install$1.call(Install.java:81)
        at org.gradle.wrapper.Install$1.call(Install.java:48)
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
        at org.gradle.wrapper.Install.createDist(Install.java:48)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63)

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
Exception in thread "main" java.util.zip.ZipException: error in opening zip file
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:228)
        at java.util.zip.ZipFile.<init>(ZipFile.java:157)
        at java.util.zip.ZipFile.<init>(ZipFile.java:171)
        at org.gradle.wrapper.Install.unzip(Install.java:239)
        at org.gradle.wrapper.Install.access$900(Install.java:27)
        at org.gradle.wrapper.Install$1.call(Install.java:81)
        at org.gradle.wrapper.Install$1.call(Install.java:48)
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
        at org.gradle.wrapper.Install.createDist(Install.java:48)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63)

    at makeError (D:codeAwesomeProjectnode_modulesexecaindex.js:174:9)
    at D:codeAwesomeProjectnode_modulesexecaindex.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async runOnAllDevices (D:codeAwesomeProjectnode_modules@react-native-communitycli-platform-androidbuildcommandsrunAndroidrunOnAllDevices.js:106:5)
    at async Command.handleAction (D:codeAwesomeProjectnode_modules@react-native-communityclibuildindex.js:192:9)
info Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

报错提示没有正确安装 Android 开发环境,以及文件打开错误

代码语言:javascript复制
Could not unzip C:Usersw.gradlewrapperdistsgradle-6.9-alldooywd8nv05k16orzxge2b1bsgradle-6.9-all.zip to C:Usersw.gradlewrapperdistsgradle-6.9-alldooywd8nv05k16orzxge2b1bs.
Reason: error in opening zip file
Exception in thread "main" java.util.zip.ZipException: error in opening zip file


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
Exception in thread "main" java.util.zip.ZipException: error in opening zip file
解决方式

在文件资源管理器中找到 C:Usersw.gradlewrapperdists 目录,删除里面的 gradle-6.9-all.zip 文件, 重新运行 yarn android 命令重新安装 Android 相关环境就好了

版本信息
  • 系统:Windows 11
  • React Native: 0.66
  • Java: 1.8.0_312
  • Javac: 1.8.0_312

0 人点赞