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

React Native打包Release失败::app:copyReactNativeVectorIconFonts任务报错求助

React Native assembleRelease打包失败(React Native Vector Icons依赖问题)

问题现象

开发React Native应用时,assembleDebug构建正常,但执行assembleRelease时失败,核心报错如下:

Task :app:copyReactNativeVectorIconFonts FAILED

FAILURE: 构建因异常失败。

  • 错误原因:
    检测到任务:app:copyReactNativeVectorIconFonts(类型为Copy)的配置存在问题:
    • Gradle 检测到路径D:\Cosas\UTN\APPMOVIL\HayEquipo\hayEquipo\android\app\build\intermediates\ReactNativeVectorIcons\fonts存在问题:任务:app:lintVitalReportRelease使用了:app:copyReactNativeVectorIconFonts的输出,但未声明显式或隐式依赖,可能导致任务执行顺序错误。
    • 任务:app:lintVitalAnalyzeRelease存在相同的依赖未声明问题。

解决方案

修改Android项目的app/build.gradle文件,通过以下任一方案解决依赖声明问题:

方案1:为lint任务添加显式依赖

让lint相关任务强制依赖copyReactNativeVectorIconFonts任务,确保执行顺序:

android {
    // 保留原有配置...

    afterEvaluate {
        tasks.named('lintVitalReportRelease') {
            dependsOn 'copyReactNativeVectorIconFonts'
        }
        tasks.named('lintVitalAnalyzeRelease') {
            dependsOn 'copyReactNativeVectorIconFonts'
        }
    }
}

方案2:指定lint任务必须在copy任务之后执行

若不想添加强依赖,可通过指定执行顺序保证copy任务先完成:

android {
    // 保留原有配置...

    afterEvaluate {
        tasks.named('lintVitalReportRelease') {
            mustRunAfter 'copyReactNativeVectorIconFonts'
        }
        tasks.named('lintVitalAnalyzeRelease') {
            mustRunAfter 'copyReactNativeVectorIconFonts'
        }
    }
}

方案3:将copy任务输出声明为lint任务的输入

符合Gradle增量构建规范,明确将字体目录作为lint任务的输入源:

android {
    // 保留原有配置...

    afterEvaluate {
        def fontsDir = file("$buildDir/intermediates/ReactNativeVectorIcons/fonts")
        tasks.named('lintVitalReportRelease') {
            inputs.dir(fontsDir)
        }
        tasks.named('lintVitalAnalyzeRelease') {
            inputs.dir(fontsDir)
        }
    }
}

修改完成后,重新执行assembleRelease即可尝试解决问题。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 21:54:52