In React Native, you can set the launcher icon for your Android app by customizing the app’s AndroidManifest.xml file and providing the necessary icon resources. Here are the steps to set the launcher icon in React Native for Android:
Step 1: Prepare Icon Resources
- Generate Icon Images:
Create launcher icon images for various screen densities. Common densities includemdpi
,hdpi
,xhdpi
,xxhdpi
, andxxxhdpi
. The icon sizes for these densities are typically 48×48, 72×72, 96×96, 144×144, and 192×192 pixels, respectively. - Place Icons in the Correct Folders:
Place the generated icon images in theres
directory of your Android project. The directory structure should look like this:
android/app/src/main/res/mipmap-mdpi/ic_launcher.png
android/app/src/main/res/mipmap-hdpi/ic_launcher.png
android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Step 2: Update AndroidManifest.xml
- Navigate to the
android/app/src/main
directory:
Open theAndroidManifest.xml
file located in theandroid/app/src/main
directory. - Update the
application
tag:
Inside the<application>
tag, set theandroid:icon
attribute to the reference of your launcher icon. This should be in the format@mipmap/ic_launcher
.
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
...
>
Step 3: Link Resources in Gradle
- Open
android/app/build.gradle
:
Open thebuild.gradle
file located in theandroid/app
directory. - Ensure the Following Block is Present:
Make sure theandroid
block contains asourceSets
block that includes theres.srcDirs
for your resources.
android {
...
sourceSets {
main {
res.srcDirs = [
'src/main/res',
...
]
}
}
}
Step 4: Build and Run
After making these changes, you can rebuild your React Native project and run it on an Android emulator or device:
npx react-native run-android
Your custom launcher icon should now be displayed when you run your React Native app on an Android device or emulator.
Show Comments