简体   繁体   中英

React-Native-Vector-Icons error on build

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

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" ^

Installation:

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

For Automatic link (RN < 0.60)

react-native link react-native-vector-icons

For Manual setup

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

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

Run the project to test the installation.

react-native run-android

Import the library.

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

Use it inside JSX. Text styles are welcome to be applied. Below is an example using also separated grid.* styling file.

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

react-native >=0.60

step:1 yarn add react-native-vector-icons

step:2 Add apply from: "../../node_modules/react-native-vector-icons/fonts.gradle" in (android/app/build.gradle)

step:3 cd android in cmd

step:4 ./gredlew clean

step:5 react-native run-android

step:6 import Icon from 'react-native-vector-icons/FontAwesome'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM