使用react-native-vector-icons,打包时会报:
FAILURE: Build failed with an exception.
* What went wrong:
Some problems were found with the configuration of task ':app:copyReactNativeVec
torIconFonts' (type 'Copy').
- Gradle detected a problem with the following location: 'D:\rnDemo7\android\a
pp\build\intermediates\ReactNativeVectorIcons\fonts'.
Reason: Task ':app:lintVitalAnalyzeRelease' uses this output of task ':app:c
opyReactNativeVectorIconFonts' without declaring an explicit or implicit depende
ncy. 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.
解决办法有两种:
一、在项目根文件夹中运行:yarn add react-native-vector-icons 对react-native-vector-icons进行修复。
二、修改您的项目文件夹 node_modules/react-native-vector-icons/fonts. gradle文件
afterEvaluate {
android.applicationVariants.all { def variant ->
def targetName = variant.name.capitalize()
++++ def lintVitalAnalyzeTask = tasks.findByName("lintVitalAnalyze${targetName}")
++++ if (lintVitalAnalyzeTask) {
++++ lintVitalAnalyzeTask.dependsOn(fontCopyTask)
++++ }
def generateAssetsTask = tasks.findByName("generate${targetName}Assets")
generateAssetsTask.dependsOn(fontCopyTask)
}
}
然后在项目根文件夹中运行:npx patch-package react-native-vector-icons 进行修复。