You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native AsyncStorage打包Release版Gradle任务依赖错误求助

解决React Native Release打包时Async Storage的Gradle依赖错误

我的React Native项目使用npx react-native run-android可正常运行,但执行./gradlew assembleRelease时,出现:react-native-async-storage_async-storage:copyReleaseJniLibsProjectAndLocalJars任务失败的错误。错误原因是该任务使用了:react-native-async-storage_async-storage:stripReleaseDebugSymbols任务的输出,但未声明显式或隐式依赖,导致执行顺序异常。

错误详情

* What went wrong:
A problem was found with the configuration of task ':react-native-async-storage_async-storage:copyReleaseJniLibsProjectAndLocalJars' (type 'LibraryJniLibsTask').
  - Gradle detected a problem with the following location: '/Users/admin/Desktop/WorkOnProjects/PartnerApp-new/node_modules/@react-native-async-storage/async-storage/android/build/intermediates/stripped_native_libs/release/out'.
    
    Reason: Task ':react-native-async-storage_async-storage:copyReleaseJniLibsProjectAndLocalJars' uses this output of task ':@react-native-async-storage_async-storage:stripReleaseDebugSymbols' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
    
    Possible solutions:
      1. Declare task ':@react-native-async-storage_async-storage:stripReleaseDebugSymbols' as an input of ':react-native-async-storage_async-storage:copyReleaseJniLibsProjectAndLocalJars'.
      2. Declare an explicit dependency on ':@react-native-async-storage_async-storage:stripReleaseDebugSymbols' from ':react-native-async-storage_async-storage:copyReleaseJniLibsProjectAndLocalJars' using Task#dependsOn.
      3. Declare an explicit dependency on ':@react-native-async-storage_async-storage:stripReleaseDebugSymbols' from ':react-native-async-storage_async-storage:copyReleaseJniLibsProjectAndLocalJars' using Task#mustRunAfter.

项目依赖列表

"dependencies": {
    "@miblanchard/react-native-slider": "^2.3.1",
    "@react-native-async-storage/async-storage": "1.21.0",
    "@react-native-community/datetimepicker": "^7.6.2",
    "@react-native-community/netinfo": "^11.3.0",
    "@react-native-community/push-notification-ios": "^1.11.0",
    "@react-native-firebase/analytics": "^18.8.0",
    "@react-native-firebase/app": "^18.8.0",
    "@react-native-firebase/messaging": "^18.8.0",
    "@react-native-google-signin/google-signin": "^11.0.0",
    "@react-native-masked-view/masked-view": "^0.3.1",
    "@react-native-picker/picker": "^2.6.1",
    "@react-navigation/bottom-tabs": "^6.5.12",
    "@react-navigation/drawer": "^6.6.7",
    "@react-navigation/native": "^6.1.10",
    "@react-navigation/native-stack": "^6.9.18",
    "@reduxjs/toolkit": "^1.9.5",
    "axios": "^0.27.2",
    "moment": "^2.29.3",
    "num-words": "^1.2.2",
    "react": "18.2.0",
    "react-native": "^0.73.0",
    "react-native-biometrics": "^2.2.2",
    "react-native-blob-util": "^0.19.6",
    "react-native-chart-kit": "^6.12.0",
    "react-native-circular-progress": "^1.3.9",
    "react-native-circular-progress-indicator": "^4.4.2",
    "react-native-contacts": "^7.0.8",
    "react-native-document-picker": "^9.1.1",
    "react-native-dotenv": "^3.4.10",
    "react-native-gesture-handler": "^2.15.0",
    "react-native-image-picker": "^7.1.0",
    "react-native-image-slider-box": "^2.0.7",
    "react-native-linear-gradient": "^2.8.3",
    "react-native-maps": "^1.10.3",
    "react-native-modal": "^13.0.0",
    "react-native-modal-datetime-picker": "^17.1.0",
    "react-native-otp-verify": "^1.1.8",
    "react-native-pdf": "^6.7.4",
    "react-native-push-notification": "^8.1.1",
    "react-native-reanimated": "^3.7.0",
    "react-native-safe-area-context": "^4.9.0",
    "react-native-screens": "^3.29.0",
    "react-native-share": "^10.0.2",
    "react-native-skeleton-placeholder": "^5.2.4",
    "react-native-sms-retriever": "^1.1.1",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-splash-screen": "^3.3.0",
    "react-native-svg": "^14.1.0",
    "react-native-svg-transformer": "^1.3.0",
    "react-native-svg-uri": "^1.2.3",
    "react-native-vector-icons": "^10.0.3",
    "react-native-walkthrough-tooltip": "^1.6.0",
    "react-native-webview": "^13.8.1",
    "react-native-youtube-iframe": "^2.3.0",
    "react-navigation": "^5.0.0",
    "react-navigation-stack": "^2.10.4",
    "react-redux": "^8.0.5",
    "to-words": "^3.3.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "^0.73.0",
    "@react-native/eslint-config": "0.73.2",
    "@react-native/js-polyfills": "^0.74.0",
    "@react-native/metro-babel-transformer": "^0.73.15",
    "@react-native/metro-config": "^0.73.0",
    "@react-native/typescript-config": "0.73.1",
    "@rnx-kit/align-deps": "^2.3.4",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "eslint-plugin-react": "^7.33.2",
    "eslint-plugin-react-native": "^4.1.0",
    "jest": "^29.2.1",
    "metro-config": "^0.80.5",
    "metro-runtime": "^0.80.5",
    "prettier": "2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "5.0.4"
  }

解决方案

方案1:升级Async Storage版本

当前使用的@react-native-async-storage/async-storage版本为1.21.0,该版本存在Gradle配置缺陷。升级到最新稳定版(如1.22.x及以上)可直接修复这个依赖声明问题。

执行升级命令:

npm install @react-native-async-storage/async-storage@latest
# 或使用yarn
yarn add @react-native-async-storage/async-storage@latest

方案2:手动添加Gradle依赖声明

若暂时不想升级版本,可在项目的android/build.gradle文件中添加以下配置,强制声明任务依赖关系:

subprojects {
    afterEvaluate { project ->
        if (project.path == ':react-native-async-storage_async-storage') {
            tasks.named('copyReleaseJniLibsProjectAndLocalJars') {
                dependsOn('stripReleaseDebugSymbols')
            }
        }
    }
}

这段代码会定位到Async Storage的子项目,确保copyReleaseJniLibsProjectAndLocalJars任务在stripReleaseDebugSymbols任务执行完成后再运行。

方案3:清理缓存后重新构建

缓存异常也可能引发此类问题,执行以下命令清理缓存后重新尝试打包:

# 清理Gradle缓存
./gradlew clean
# 清理npm缓存
npm cache clean --force
# 删除依赖目录和锁文件
rm -rf node_modules package-lock.json
# 重新安装依赖
npm install
# 执行Release打包
./gradlew assembleRelease

内容的提问来源于stack exchange,提问作者Praveen K B

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 23:45:55