1

I created the folders:

app_name/res/drawable-hdpi
app_name/res/drawable-mdpi
app_name/res/drawable-ldpi

I put icons 72x72 in hdpi, 48x48 in mdpi, and 36x36 in ldpi. I named the png icons: icon.png

I compiled and ran it and the icons didn't change. So then I went to AndroidManifest.xml and changed the icon parameter:

<application
        android:icon="@drawable-ldpi/icon"
...

However I get this error:

Error: No resource found that matches the given name (at 'icon' with value '@drawable-ldpi/icon'). AndroidManifest.xml

Any tips?

Michał Powaga
  • 22,561
  • 8
  • 51
  • 62
Ron I
  • 4,090
  • 8
  • 33
  • 64
  • You may need to add res.srcDirs to you sourceSets > main in your build.gradle file. See solution here - http://stackoverflow.com/a/17097436/857681 . I was having the same issue and this fixed it. Once changed run gradle clean && gradle build in your project root. – speedynomads Jul 24 '13 at 22:07

2 Answers2

6

adding the dpi to the drawable is invalid. You should just be able to set it like so in the manifest:

<Application
  ...
  android:icon="@drawable/ic_launcher" > 
  <!-- change ic_launcher to whatever your png is named -->

The typical folder structure is as follows:

/
  AndroidManifest.xml
  /res
    /drawable-ldpi
      ic_launcher.png       # 36x36
    /drawable-mdpi
      ic_launcher.png       # 48x48
    /drawable-hdpi
      ic_launcher.png       # 72x72

Once you've done this, you'll probably need to do a clean (eclipse -> project -> clean), but you'll know it was successful if a line like this appears in your /gen/R.java file:

public static final int ic_launcher = 0x...;

If it isn't, you can delete the R.java file and the ADT will immediately panic and rebuild it from scratch, incorporating your new drawables.

As a final note, sometimes the emulator seems to cling to the old icon - the clean should make it change, but if it doesn't, go into settings and uninstall the application and then run again from eclipse, everything should REALLY be clean (the same applies to actual devices as well)

NOTE the answer now includes the comments below

JRaymond
  • 11,625
  • 5
  • 37
  • 40
1

make sure you have refreshed your Android project. You might try changing the name of your icon files to "ic_launcher.png" which is the name used now.

Alan Moore
  • 6,525
  • 6
  • 55
  • 68
  • Thanks. However we are supposed to supply different image sizes for different resolution screens. I'd like to avoid that solution and use the one properly supported. Strange. – Ron I Apr 19 '12 at 22:24
  • Also - how would I 'refresh' my Android project? You mean run it again? – Ron I Apr 19 '12 at 22:27
  • If you right click on your project in Package Explorer on the left you can choose Refresh and it should find any new files you've added or updated. – woodstock365 Apr 19 '12 at 22:40
  • thanks! :) its not showing the default icon, but its also not showing the icon i put in the folder haha. – Ron I Apr 19 '12 at 23:09
  • Did you try changing the icon file name and removing the line from your manifest file? – Alan Moore Apr 19 '12 at 23:40
  • Can you put your manifest file into your original question, I can't read it in the comment very well. Also, it's not clear to me if you ever tried changing the names of your icon files from icon.png to ic_launcher.png -- your comments suggest that you didn't. – Alan Moore Apr 20 '12 at 20:56