解决 react-native-community_async-storage 编译出现 compileDebugJavaWithJavac 错误
最近运行项目有时候会出现如下错误:
> Task :@react-native-community_async-storage:compileDebugJavaWithJavac FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
19 actionable tasks: 1 executed, 18 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':@react-native-community_async-storage:compileDebugJavaWithJavac'.
> Could not create service of type DefaultGeneralCompileCaches using GradleScopeCompileServices.createGeneralCompileCaches().
* 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 6s
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':@react-native-community_async-storage:compileDebugJavaWithJavac'.
> Could not create service of type DefaultGeneralCompileCaches using GradleScopeCompileServices.createGeneralCompileCaches().
* 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 6s
at checkExecSyncError (child_process.js:621:11)
at execFileSync (child_process.js:639:15)
at runOnAllDevices (/data/newapp/test/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:74:39)
at buildAndRun (/data/newapp/test/dongwaiyu/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:158:41)
at /data/newapp/test/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:125:12
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Command.handleAction (/data/newapp/test/node_modules/@react-native-community/cli/build/cliEntry.js:160:7)
执行如下命令即可解决
yarn add @react-native-community/async-storage && react-native link @react-native-community/async-storage
博客补充更新,作者又迁窝了将仓库从原来的 @react-native-community/async-storage 迁移到 @react-native-async-storage/async-storage
新仓库的代码地址:https://github.com/react-native-async-storage/async-storage
yarn add @react-native-async-storage/async-storage
React Native 0.60 以下可能还需要执行如下命令
react-native link @react-native-async-storage/async-storage
最后,项目中使用到 @react-native-community_async-storage 或者 @react-native-community/async-storage 的地方别忘记改为 @react-native-async-storage/async-storage
暂时没发现其他迁移差异,如果还有问题可以回复本博客,我看到就会及时回复你的
小哥哥,你能看到这条信息吗 我按照你的方式安装了 还是不行 还是报这个错误
作者又迁窝了。?
yarn add @react-native-async-storage/async-storage
这个命令 也已经安装了 还是报同样的错误
项目的 RN 版本 0.60 以下的话执行一下 link 试试
react-native 0.61的版本,报这个错,运行这个命令还是报这个错啊。
Execution failed for task ‘:@react-native-async-storage_async-storage:compileDebugJavaWithJavac’.
> Compilation failed; see the compiler error output for details.
OS: Windows 10
Binaries:
Node: 16.13.2 – C:\Program Files\nodejs\node.EXE
Yarn: 1.22.18 – ~\AppData\Roaming\npm\yarn.CMD
npm: 8.1.2 – C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: AI-212.5712.43.2112.8609683
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.3 => 0.61.3
安装了 @react-native-async-storage/async-storage 新依赖后
npm install @react-native-async-storage/async-storage
记得将 @react-native-community_async-storage 依赖卸载,并且在代码中将 @react-native-community_async-storage 的引用替换为 @react-native-async-storage/async-storage
npm uninstall @react-native-community_async-storage
按你这个逻辑,提示这个版本错误。这个问题,该如何解决呢?
@react-native-async-storage/async-storage 安装替换后还是没办法解决吗?