26

I just converted my app icon to be compatible with android o's adaptive icons using the Image Asset Studio in android studio

when I run my project now on my device running API 25 I get the default green android icon and not my icon.

this is my manifest

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:allowBackup="false"
    android:roundIcon="@mipmap/ic_launcher_round"
    tools:replace="allowBackup"
    tools:ignore="GoogleAppIndexingWarning">

and these are the files the image asset studio created

enter image description here

Is this just an Android Studio bug or did I miss something?

tyczj
  • 66,691
  • 50
  • 172
  • 271

5 Answers5

36

I had the same trouble, and solved it by renaming my mipmap-anydpi directory to mipmap-anydpi-v26.

Apparently the ic_launcher.xml file confuses older Android versions, and this hides it from all but O. At any rate, my icons now work on all versions (down to SDK 11, at least).

String
  • 5,633
  • 2
  • 27
  • 39
  • 5
    I have the v26 directory and still I get the default green android on legacy APIS. – JPM Feb 12 '18 at 17:58
  • @JPM, I suggest you open a new question with some source code (like what the OP did here). I'm pretty confident that this technique works as advertised, but it's impossible to guess what might be going wrong in your app. – String Feb 12 '18 at 21:21
  • 1
    turns out I still had the mipmap-anydpi directory and the mipmap-anydpi-v26. Once I deleted the mipmap-anydpi then the icons for all versions were correct. – JPM Feb 22 '18 at 17:18
  • Is this still an issue? I'm using `mipmap-anydpi-v26` and users say that the rootless pixel launcher doesn't show the adaptive icon and I'm wondering if it is because of that. – casolorz Mar 12 '18 at 14:28
  • Appears to still be an issue. – casolorz Mar 12 '18 at 14:48
  • @casolorz if it's only happening on Rootless Pixel Launcher then it may a bug there. Perhaps contact the dev and pursue that direction? – String Mar 12 '18 at 17:47
  • What is strange is that the user sent me a screenshot and other apps seem to have adaptive icons just fine on it. I don't have a phone that can run it though so I haven't tested it myself. – casolorz Mar 12 '18 at 17:48
  • Just following up on this, @casolorz: I installed Rootless Pixel Launcher on an API 25 device (Nexus 6), and the icons of various of my apps that use the `anydpi-v26` technique in this answer work fine. Whatever is going on with your app, I suspect it's unrelated; as I suggested to JPM above, you might consider opening a new issue. – String Mar 13 '18 at 05:06
  • Thanks for testing that. I'll need to see if I can find a Nexus 6 to test on. – casolorz Mar 13 '18 at 17:58
  • In my case the adaptive icon showed up correctly after I deleted the `drawable-v24` folder with an identically named (conflicted) .xml resource in it. – Alex Hall Jul 17 '18 at 23:50
  • Cannot state enough to delete the app manually from the device before trying again. – Jonathan Maim Nov 13 '20 at 12:02
16

Solution is to have mipmap-anydpi-v26/ic_launcher.xml for adaptive icons applicable for API level 26 and above and for other API levels put ic_launcher.png (Note: Not ic_launcher.xml) in all mimpap folders.


Explanation:

Here is the basic problem mipmap-anydpi take precedence over all other mipmap-*. So if resource is found in mipmap-anydpi it will always take preference. Now mipmap-anydpi-v26 is a filter above this which says resources from mipmap-anydpi-v26 will always be picked irrespective of devices density only if API level is 26 or more (Oreo).

Now you manifest has android:icon="@mipmap/ic_launcher"

If your device has API level 26 or above android will choose to use mipmap-anydpi-v26/ic_launcher.xml and everything works fine.

The problem happens when API level is less than 26. Android stats looking for resource named ic_launcher. It will never go and search in mipmap-anydpi-v26 because of API level constraint. Next, it would look for the resource in mipmap-anydpi and if not there then the actual density resource Eg. mipmap-mdpi.

Next, you cannot give ic_launcher.xml to android devices less than sdk 26 because it does not know what adaptive icons is.

So the solution is to have mipmap-anydpi-v26/ic_launcher.xml for adaptive icons applicable for API level 26 and above and for other API levels put ic_launcher.png (Note: Not ic_launcher.xml) in all mimpap folders.

Aniket Thakur
  • 58,991
  • 35
  • 252
  • 267
2

I have been faced same issue and resolved as below.

Put your ic_launcher.xml and ic_launcher_round.xml should be in mipmap-anydpi-v26 (make sure you should not have ic_launcher.png/jpg or ic_launcher_round.png/jpg in same folder).

Put your ic_launcher.png should be in mipmap-hdpi/mdpi/xhdpi/xxhdpi/xxxhdpi (make sure you should not have ic_launcher.xml and ic_launcher_round.xml in these same folder).

By doing this, You will not get any errors building/running project.

Hope it helps some one who are same issue...

Ashok
  • 43
  • 1
  • 8
0

If still not working, check your XML schmema in , if you use auto import from Android studio, it will not work, it should be /apk/res/android. Here is the code:

<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
  <background android:drawable="@mipmap/ic_launcher_background"/>
  <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
louis bui
  • 21
  • 4
0

I will conclude this in a very simple manner.

I used android studio just to generate the sources (background and foreground layers of images) which is used in my config.xml file.

So it will look like this :-

<icon background="resources/android/icon/ldpi_background.png" density="ldpi" foreground="resources/android/icon/ldpi_foreground.png">

The above configuration will work well with Android API level > 25.

Here comes the main problem for legacy icon in old versions of android

As per cordova official documentation - adaptive icons are not supported in old versions of android - and with above config.xml it will pick foreground part only as a fallback icon which is the reason your icon doesn't look nice in old versions.

So i applied the following fix for that ( as per cordova official documentation)

Add the src attribute with static image icons - so in old versions instead of using the fallback icon it will use that icon and for latest versions it will give priority to adaptive icons and hence problem will be solved for both.

config will look like this after the fix :-

<icon background="resources/android/icon/ldpi_background.png" density="ldpi" foreground="resources/android/icon/ldpi_foreground.png" src="resources/android/icon/drawable-ldpi-icon.png"/>
Dheeraj
  • 231
  • 2
  • 3