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

React Native项目Async Storage模块编译失败问题求助

React Native Async-Storage编译失败问题

问题描述

应用此前运行正常,截至11月5日(周五)无异常,今日启动时突然报错:

Task :react-native-community_async-storage:compileDebugJavaWithJavac FAILED

  • What went wrong:
    Execution failed for task ':react-native-community_async-storage:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

相关配置信息

依赖版本:

"@react-native-community/async-storage": "^1.7.1"

Android构建配置:

buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"

Gradle版本:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip

解决步骤

  1. 查看完整错误日志
    在Android项目根目录执行./gradlew assembleDebug --stacktrace,或直接在Android Studio的Build窗口查看详细编译报错,精准定位冲突点。

  2. 清理缓存

    • 清理Android构建缓存:./gradlew clean
    • 重置React Native缓存:npx react-native start --reset-cache
  3. 升级Async-Storage版本
    当前使用的1.7.1版本较旧,易出现兼容性问题。建议升级到同分支稳定版,执行:

    npm install @react-native-community/async-storage@^1.12.1 --save
    

    若RN版本低于0.60,需重新链接:npx react-native link @react-native-community/async-storage

  4. 统一Support库版本
    在项目根目录build.gradle中添加强制配置,确保所有依赖的Support库版本统一为28.0.0,避免冲突:

    subprojects {
        afterEvaluate { project ->
            if (project.hasProperty('android')) {
                android {
                    configurations.all {
                        resolutionStrategy.eachDependency { details ->
                            if (details.requested.group == 'com.android.support'
                                    && !details.requested.name.contains('multidex')) {
                                details.useVersion "28.0.0"
                            }
                        }
                    }
                }
            }
        }
    }
    
  5. 调整Gradle版本
    尝试将Gradle升级到5.6.4(与SDK28兼容的稳定版),修改gradle/wrapper/gradle-wrapper.properties:

    distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
    

内容的提问来源于stack exchange,提问作者Tafsir Ahamed

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 18:01:16