构建时 React-Native-Vector-Icons 错误 [英] React-Native-Vector-Icons error on build

查看:74
本文介绍了构建时 React-Native-Vector-Icons 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了 React Native Vector Icons,但是当我运行react-native run-android"时它在构建时失败,出现这个错误:

I have installed React Native Vector Icons, but it fails on build when i run "react-native run-android", with this error:

启动失败:构建文件C:\projects\musicapp\android\app\build.gradle":3:意外标记:应用@第 3 行,第 1 列.申请自:../../node_modules/react-native-vector-icons/fonts.gradle"^

startup failed: build file 'C:\projects\musicapp\android\app\build.gradle': 3: unexpected token: apply @ line 3, column 1. apply from: "../../node_modules/react-native-vector-icons/fonts.gradle" ^

推荐答案

安装:

npm install --save react-native-vector-icons

对于自动链接 (RN <0.60)

react-native link react-native-vector-icons

手动设置

编辑android/app/build.gradle(不是android/build.gradle)并添加以下内容:

Edit android/app/build.gradle ( NOT android/build.gradle ) and add the following:

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

运行项目以测试安装.

react-native run-android

导入库.

import Icon from ‘react-native-vector-icons/FontAwesome’

在 JSX 中使用它.欢迎使用文本样式.下面是一个使用同样分隔的 grid.* 样式文件的示例.

<View>
   <Icon name='area-chart' color="green" size={20} />
   <Text>Enjoy Coding.</Text>
</View>

这篇关于构建时 React-Native-Vector-Icons 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆