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

React Native Vector Icons导致Release构建失败问题求助

React Native Android Release构建失败:Gradle任务依赖冲突问题

我用npx react-native init AppName创建了React Native项目,Debug模式运行完全正常,但在android目录下执行./gradlew assembleRelease命令时构建失败,错误信息如下:

> Task :app:copyReactNativeVectorIconFonts FAILED

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':app:copyReactNativeVectorIconFonts' (type 'Copy').
  - Gradle detected a problem with the following location: '/Projects/AppName/android/app/build/intermediates/ReactNativeVectorIcons/fonts'.
    
    Reason: Task ':app:lintVitalAnalyzeRelease' uses this output of task ':app:copyReactNativeVectorIconFonts' 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 ':app:copyReactNativeVectorIconFonts' as an input of ':app:lintVitalAnalyzeRelease'.
      2. Declare an explicit dependency on ':app:copyReactNativeVectorIconFonts' from ':app:lintVitalAnalyzeRelease' using Task#dependsOn.
      3. Declare an explicit dependency on ':app:copyReactNativeVectorIconFonts' from ':app:lintVitalAnalyzeRelease' using Task#mustRunAfter.

* 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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/8.0.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 4s
214 actionable tasks: 7 executed, 207 up-to-date

项目依赖(package.json)

{  
  "name": "App Name",  
  "version": "0.0.1",  
  "private": true,  
  "scripts": {    
    "android": "react-native run-android",    
    "ios": "react-native run-ios",    
    "lint": "eslint .",    
    "start": "react-native start",    
    "test": "jest"  
  },  
  "dependencies": {    
    "@react-native-async-storage/async-storage": "^1.19.0",    
    "@react-navigation/bottom-tabs": "^6.5.8",    
    "@react-navigation/native": "^6.1.7",    
    "@react-navigation/native-stack": "^6.9.13",    
    "@reduxjs/toolkit": "^1.9.5",    
    "axios": "^1.4.0",    
    "react": "18.2.0",    
    "react-native": "0.72.1",    
    "react-native-linear-gradient": "^2.7.3",    
    "react-native-safe-area-context": "^4.6.3",    
    "react-native-screens": "^3.22.0",    
    "react-native-splash-screen": "^3.3.0",    
    "react-native-vector-icons": "^9.2.0",    
    "react-redux": "^8.1.1"  
  },  
  "devDependencies": {    
    "@babel/core": "^7.20.0",    
    "@babel/preset-env": "^7.20.0",    
    "@babel/runtime": "^7.20.0",    
    "@react-native/eslint-config": "^0.72.2",    
    "@react-native/metro-config": "^0.72.7",    
    "@tsconfig/react-native": "^3.0.0",    
    "@types/metro-config": "^0.76.3",    
    "@types/react": "^18.0.24",    
    "@types/react-test-renderer": "^18.0.0",    
    "babel-jest": "^29.2.1",    
    "eslint": "^8.19.0",    
    "jest": "^29.2.1",    
    "metro-react-native-babel-preset": "0.76.5",    
    "prettier": "^2.4.1",    
    "react-native-dotenv": "^3.4.9",    
    "react-test-renderer": "18.2.0",    
    "typescript": "4.8.4"  
  },  
  "engines": {    
    "node": ">=16"  
  }
}

开发环境

  • macOS Ventura 13.4.1
  • NodeJS - 18.15.0
  • Yarn - 1.22.19
  • Android Studio Electric Eel | 2022.1.1 Patch 2(Build #AI-221.6008.13.2211.9619390)
  • Java 17.0.6 LTS

解决方案

方案1:显式声明任务依赖(推荐)

打开android/app/build.gradle文件,在文件末尾添加以下代码,让lintVitalAnalyzeRelease任务明确依赖copyReactNativeVectorIconFonts:

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

或者使用mustRunAfter确保执行顺序:

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

方案2:升级react-native-vector-icons版本

当前使用的9.2.0版本可能存在Gradle任务配置缺陷,升级到最新稳定版可修复该问题:

yarn upgrade react-native-vector-icons@latest

升级完成后重新执行构建命令即可。

方案3:临时禁用Release版Lint检查(仅用于快速测试)

如果需要紧急构建测试包,可临时关闭Release模式下的Lint检查,在android/app/build.gradle的android代码块中添加:

android {
    // ...其他已有配置
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
}

注意:该方案会跳过代码质量检查,不建议用于正式发布包。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 01:49:49