dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Android App Icon Configuration Not Working

Open ksmit323 opened this issue 11 months ago • 6 comments

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:

  1. Create a Dioxus project with Android target
  2. 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"
]
  1. Create PNG icons in specified sizes
  2. Run dx build --platform android
  3. Install with adb install target/.../app-debug.apk
  4. 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

ksmit323 avatar Feb 04 '25 10:02 ksmit323

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:

  1. I created five square PNG images at these standard Android icon sizes:

    • 48x48 (mdpi)
    • 72x72 (hdpi)
    • 96x96 (xhdpi)
    • 144x144 (xxhdpi)
    • 192x192 (xxxhdpi)
  2. I replaced the default images in the mipmap folders inside the target/ directory. After running dx build, these can be found at:

   target/dx/your-app-name/debug/android/app/app/src/main/res
  1. My ic_launcher.xml file was referencing a missing ic_launcher_foreground.xml file. I think this caused Android to fall back to the default green droid icon. To fix this, I deleted the ic_launcher.xml file:
rm target/dx/your-app-name/debug/android/app/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
  1. After that, I cleaned, rebuilt and reinstalled and it worked! However, I rebuilt with the ./gradlew executable instead:
./gradlew clean
./gradlew assembleDebug
adb install app/build/outputs/apk/debug/app-debug.apk

ksmit323 avatar Feb 07 '25 07:02 ksmit323

I'm wondering whether there is a more integrated solution after recent upgrades to avoid the manual configuration?

Weiming-Hu avatar Apr 04 '25 03:04 Weiming-Hu

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.

gerum100 avatar Apr 04 '25 09:04 gerum100

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.

Weiming-Hu avatar Apr 04 '25 14:04 Weiming-Hu

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.

YinMo19 avatar Apr 10 '25 23:04 YinMo19

I'm new to Android dev so @YinMo19's solution definitely helped me. Thank you! It worked on my Ubuntu.

Weiming-Hu avatar Apr 13 '25 18:04 Weiming-Hu