Lucas Lobosque
Lucas Lobosque

Reputation: 399

Cordova/Phonegap - Android: Icon not updating

I'm using cordova 3.3.0 (CLI) and I replaced the icons in the www/res/icons/android folder, as per docs instructions (http://cordova.apache.org/docs/en/3.3.0/config_ref_images.md.html). The problem is, when I build and send the app to my phone (cordova run android), the icon is still the default one, even if I uninstall the app from my phone before installing again. Any advise on how to solve this? Thanks!

Upvotes: 7

Views: 10765

Answers (7)

Chris Hubbard
Chris Hubbard

Reputation: 564

As of Cordova 8.0.0, this still seems to be a problem. I replaced the default cordova icons located in res\icon\android with my own (keeping the file names in tact) and expected that the build would use those icons, but it did not.

The fix for me was to specify the path to the icons explicitly in the platform section of config.xml.

<platform name="android">
    <allow-intent href="market:*" />
    <icon density="ldpi" src="res/icon/android/icon-36-ldpi.png" />
    <icon density="mdpi" src="res/icon/android/icon-48-mdpi.png" />
    <icon density="hdpi" src="res/icon/android/icon-72-hdpi.png" />
    <icon density="xhdpi" src="res/icon/android/icon-96-xhdpi.png" />
</platform>

Upvotes: 1

Kevin Mauro
Kevin Mauro

Reputation: 57

Run this python script in the same folder that as the platforms & www folders. It will replace all instances of "icon.png" with your desired image. In my case, the logo is stored at ./www/img/log1.png. Tested on Ubuntu, may work on other platforms.

import os; 
fileList = os.popen("find ./ -name icon.png").read();
files=fileList.split("\n");
for f in files:
    if(f!=files[len(files)-1]):
        print(f);
        os.system("cp ./www/img/logo1.png "+f+";");

I was surprised to find Cordova will automatically scale the logo for you, so don't waste time making multiple pixel densities for each image. Just use a really big / high pixel-density image and it will be scaled for you for the lower density screens.

Upvotes: 0

Adam Maloney
Adam Maloney

Reputation: 537

A restart worked for me. The device must cache them?

Upvotes: 3

Elixander Chen
Elixander Chen

Reputation: 101

I'm using version 4.2.

There were 2 different instances of this happening and 2 different solutions.

First instance) I make the icon changes in the platforms\android\ant-build\res folder.

Second instance) Phonegap was wrongly building ios icons into the android\res folder. After going through the logs using phonegap build android --verbose, I notice it was copying the ios icon from \www\res\icon\ios\icon-72.png into android\ant-build\res\drawable-hdpi\icon.png. You'll want to read the logs and see if it's misbehaving.

Good luck!

Upvotes: 0

Kristian Ivanov
Kristian Ivanov

Reputation: 111

Try simply restarting your phone. It sounds ridiculous, but it fixed the same issue for me.

Upvotes: 3

Makeen A. Sabree
Makeen A. Sabree

Reputation: 375

I am using http://ionicframework.com/ to build my app and it uses cordova. I ran into the same issue as you and was able to fix it very easily.

What I suggest first is going to the root of your project and running the following:

grep -nr "icon.png" *

This will list all the references to the icon.png and can give you an idea of where the files are being copied to. I too updated my android/res/drawable folders to no luck. But after running the grep command above I noticed that the icons were being copied into:

/platforms/android/ant-build/res/drawable-xhdpi/icon.png

I navigated to this folder and noticed that the images were the default cordova png images. I updated each drawable with my icons and now all is well.

Hopefully this can help resolve your issue. Best of luck!

Upvotes: 12

Kaan Soral
Kaan Soral

Reputation: 1645

It seems the www/res/icons aren't really functional, I've seen no indication that they are functional, here is a useful article: http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/

The best thing to do is to write a script once to copy them into the right place

Upvotes: 2

Related Questions