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

React Native v0.61.5在Android Studio Hedgehog构建AAPT2报错求助

React Native v0.61.5 Android构建AAPT2链接错误排查方案

错误信息

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
   > AAPT2 aapt2-4.2.1-7147631-osx Daemon #0: Unexpected error during link, attempting to stop daemon.
     This should not happen under normal circumstances, please file an issue if it does.

* 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 7s

排查与解决步骤

  • 适配Gradle及Android Build Tools版本
    React Native 0.61.5对新工具链兼容性有限,需降级到匹配版本:

    1. 项目根目录build.gradle(项目级)中,修改gradle插件版本:
      buildscript {
          dependencies {
              classpath 'com.android.tools.build:gradle:3.5.4'
          }
      }
      
    2. 修改gradle/wrapper/gradle-wrapper.properties中的Gradle版本:
      distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
      
  • 锁定AAPT2版本
    在项目级build.gradle的buildscript依赖中添加AAPT2指定版本,避免自动拉取高版本:

    buildscript {
        dependencies {
            // 已有的gradle插件依赖
            classpath 'com.android.tools.build:gradle:3.5.4'
            // 新增锁定AAPT2版本
            classpath 'com.android.tools.build:aapt2:4.0.1-6197926'
        }
    }
    
  • 清理构建缓存

    1. 终端执行清理命令:
      ./gradlew clean
      
    2. Android Studio中清除缓存:File -> Invalidate Caches...,勾选Clear file system cache and local history后点击Invalidate and Restart
  • 检查资源文件合法性

    • 排查res目录下XML资源(如layout、values文件)是否存在语法错误(未闭合标签、无效属性等)
    • 检查图片资源是否损坏、文件名是否包含特殊字符(如中文、空格)
  • 切换兼容JDK版本
    React Native 0.61.5建议使用JDK 8,在Android Studio中设置:File -> Project Structure -> SDK Location,选择JDK 8的安装路径

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 02:35:12