Android App Icon Configuration Not Working
Problem
Unable to configure custom app icon for Android builds using Dioxus.toml file. The default Android photo icon is always used regardless of configuration attempts.
Steps To Reproduce
Steps to reproduce the behavior:
- Create a Dioxus project with Android target
- Configure Dioxus.toml with icon paths:
[bundle]
icon = [
"assets/icons/icon-32x32.png",
"assets/icons/icon-128x128.png",
"assets/icons/[email protected]",
"assets/icons/icon-256x256.png",
"assets/icons/icon-512x512.png"
]
- Create PNG icons in specified sizes
- Run
dx build --platform android - Install with
adb install target/.../app-debug.apk - Observe that app still uses default Android photo icon
Expected behavior
The app should display the custom icon specified in Dioxus.toml when installed on an Android device. Instead, it always shows the default Android photo placeholder icon.
Environment:
- Dioxus version: 0.6.2
- Rust version: 1.84
- OS info: Linux (Ubuntu 24.04)
- App platform: Android
For anyone who is looking for a fix, I was able to get this to work. Not through the Dioxus.toml but through changing the default "droid" image in the mipmap files in the target directory that dx build creates.
This is for Linux, fyi, and assumes you already used dx build --platform android to create the target directory.
The short answer is:
-
I created five square PNG images at these standard Android icon sizes:
- 48x48 (mdpi)
- 72x72 (hdpi)
- 96x96 (xhdpi)
- 144x144 (xxhdpi)
- 192x192 (xxxhdpi)
-
I replaced the default images in the
mipmapfolders inside thetarget/directory. After runningdx build, these can be found at:
target/dx/your-app-name/debug/android/app/app/src/main/res
- My
ic_launcher.xmlfile was referencing a missingic_launcher_foreground.xmlfile. I think this caused Android to fall back to the default green droid icon. To fix this, I deleted theic_launcher.xmlfile:
rm target/dx/your-app-name/debug/android/app/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
- After that, I cleaned, rebuilt and reinstalled and it worked! However, I rebuilt with the
./gradlewexecutable instead:
./gradlew clean
./gradlew assembleDebug
adb install app/build/outputs/apk/debug/app-debug.apk
I'm wondering whether there is a more integrated solution after recent upgrades to avoid the manual configuration?
I'm not part of the dioxus team, but I have digged through the code and it clearly seems like there is so support for such a feature. In the build_android_app_dir method it will only copy the static files into the target directory and in android_gradle_bundle,which seems like the correct place to implement such a feature (because in the corresponding build_desktop method the icon is used), there is no code that access the bundle icon.
Thank you! I wish I can be more fluent in rust so that I can submit a PR. But just started learning several months ago. Will keep monitoring this thread then.
I write a shell script that to make it easiler.
#! /bin/sh
# clean first
cargo clean
# bundle with dx
dx bundle --platform android --release
# into the release folder
cd target/dx/<your project name>/release/android/app/
# do clean and replace the icons, then build
./gradlew clean
find app/src/main/res -name "*.webp" -type f -delete
cp -r <your icon path>/res app/src/main/
rm app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
./gradlew assembleRelease
# generate the key to sign the apk
# keytool -genkeypair \
# -v -keystore <path to your jks> \
# -keyalg RSA -keysize 2048 \
# -validity 10000 \
# -alias ClockMobile \
# -storepass <your key> \
# -dname "CN=<your name>, OU=<dev>, O=<company>, L=<city>, C=<country>"
# optimize the apk
zipalign -v -p 4 \
app/build/outputs/apk/release/app-release-unsigned.apk \
app-release-aligned.apk
# sign and install
apksigner sign \
--ks <path to your jks> \
--ks-pass pass:<your key> \
--out app-release-signed.apk \
app-release-aligned.apk
# if you dont need install, you can change it to mv it below workspace.
adb install -r app-release-signed.apk
it runs well in my MacOS and android. Dont forget to replace the info in <> tag. Hope it helps you.
I'm new to Android dev so @YinMo19's solution definitely helped me. Thank you! It worked on my Ubuntu.