I had the same issue when I tried to add icons to my react native android project. I'll mention everything from the beginning. (Note: I am using VSCode in this part)
First follow the Official React Native documentation and try to run the app on your phone using USB.
Open the android folder using Android Studio which will automatically build the files correctly.
Use the following command to run the app on your android device.
npx react-native run-android
At this point, the app should be working properly on your android device. Please do not continue to work on the icons if this part doesn't work yet.
Now to add the icons to react native. Install the following:
npm install react-native-vector-icons --save
npm install -D @types/react-native-vector-icons
Open android/app/build.gradle (not android/build.gradle) and enter the following at the top:
import org.apache.tools.ant.taskdefs.condition.Os
Now enter this code inside the android block of the same file:
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
Enter this code inside the dependencies block of the same file:
implementation 'com.google.android.material:material:1.5.0' // Replace 1.5.0 with the latest version
Now open this build.gradle file in Android Studio (open android/app/build.gradle, not android/build.gradle) and check somewhere if it says to Sync the changes or code and click on it.
Wait till the code is synced.
Kill the VScode terminal, open a new terminal in either powershell or CMD.
Run the following command to rebuild the app on your android phone.
npx react-native run-android
If there are issues, try the following in powershell terminal:
cd android
./gradlew clean
cd ..
Rebuild the app again.
Here is my code for App.tsx if you need reference for the code.
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React from 'react';
import {
SafeAreaView,
StatusBar,
StyleSheet,
View,
} from 'react-native';
import { Colors } from 'react-native/Libraries/NewAppScreen';
import { Text } from './components/Text';
import Icon from 'react-native-vector-icons/FontAwesome';
function App(): JSX.Element {
return (
<SafeAreaView style={Colors.darker}>
<StatusBar barStyle={'light-content'} backgroundColor={Colors.darker} />
<View style={{ backgroundColor: Colors.black }}>
<Icon.Button color="white" name="facebook">Login with Facebook</Icon.Button>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
});
export default App;
Here is a page I referred to which helped me a lot: https://blog.logrocket.com/react-native-vector-icons-fonts-react-native-app-ui/
This is what I have done to enable icons in React Native and I do hope it has helped you :)