58

In Android Studio 3.0, once we create a project, a folder named mipmap-anydpi-v26 is automatically created in the res directory. What actually does it do? Why do we need it? How will we utilize it for development purposes?

Also, there are two XML files automatically created in this folder after project setup. Why do these XML files reside in a mipmap folder? I thought we should keep all XML files in a drawable folder instead of mipmap.

Pang
  • 9,564
  • 146
  • 81
  • 122
0xAliHn
  • 18,390
  • 23
  • 91
  • 111

3 Answers3

41

Android Studio 3 creates an adaptive icon for your app which is only available in SDK 26 and up. Launcher icons should be put into the mipmap folders.

If you look at your manifest, you can see that it references ic_launcher

android:icon="@mipmap/ic_launcher"

If you look in your mipmap folder, you see your normal 5 different launcher icons which will be used for anything lower than SDK 26. For SDK 26 and up, it uses the XML files from the anydpi-v26 folder to make use of adaptive icon.

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@drawable/ic_launcher_background"/>
    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Pang
  • 9,564
  • 146
  • 81
  • 122
tyczj
  • 71,600
  • 54
  • 194
  • 296
  • 1
    Does this imply that your "adaptive icon" only needs to be provided in one image size, and it will auto-size based on the current dpi/resolution, or is that not true? If the former, where physically do I place the adaptive icon pair of images? If the latter, does this mean I still need to split up the image into multiple sizes and put them in their respective folders? (Mind you I'm using Unity3d, so I'm not benefitting from what Android Studio provides automatically). – vargonian Sep 18 '17 at 21:38
  • You still need to use different size icons but they go in the mipmap folder under the respected dpi folder – tyczj Sep 19 '17 at 13:00
  • Thanks. I'm still confused why the "drawable-" folders are just replaced by seemingly equivalent "mipmap-" folders. I got it working, though. – vargonian Sep 20 '17 at 17:56
  • @vargonian https://android-developers.googleblog.com/2014/10/getting-your-apps-ready-for-nexus-6-and.html – tyczj Sep 21 '17 at 14:37
  • My icon is cropped by edges. I want to centralize it but ic_launcher.xml does not provide that. I put all densities of my icon to the related folders. But ic_launcher.xml crops my icon so it is not possible to see all of my icon. – Hilal Oct 26 '20 at 16:05
19

Both answers above give pretty good summary of what mipmap-anydpi-v26 folder does but I feel why part is missing. So heres my 2 cents.

anydpi: These resources take precedence in any dpi. So even if you have mipmap-hdpi or mipmap-mdpi matching with current devices density, resource from mipmap-anydpi will always be picked up.

anydpi-v26: This is an additional filter over just anydpi. This says resources will always be picked up from anydpi-v26 regardless of devices density only if SDK/API level is 26 or higher(Oreo).

So you can have mipmap-anydpi-v26 or drawable-anydpi-v26. All resource folders will follow above logic.

Now that we know the answer of "why mipmap-anydpi-v26"? lets try to understand why "mipmap-anydpi-v26/ic_launcher.xml".

This is because ic_launcher.xml is used to describe adaptive icon for your app which is only available in SDK 26 and up as mentioned by other answers. Hope this helps.

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
  • 3
    There seem to be more to it. Since I changed to only support v28 and beyond I renamed `mipmap-anydpi-v26` to `mipmap-anydpi` — but that messed up the adaptive icons. – Martin Jul 16 '21 at 08:49
8

I have found an explanation about this, here is some context:

To add an adaptive icon that replaces all PNGs on API 26+ devices, you’ll add a res/mipmap-anydpi-v26/ic_launcher.xml file that looks like this:

<adaptive-icon
    xmlns:android="http://schemas.android.com/apk/res/android">
  <background android:drawable="@drawable/ic_launcher_background"/>
  <foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>

By placing it in the mipmap-anydpi-v26 folder, the resource system will use it in preference over any files in the other dpi folders (exactly what you want, since this file is replacing all of them) and that it should only be used in API 26+ devices.

0xAliHn
  • 18,390
  • 23
  • 91
  • 111
  • 5
    But when i see the content of the XML, it points to a Vector Graphics Code Block, Just to be true to heart, i am new to vector graphics and would request anyone on how to handle with the current PNG, as my icon is somewhat complicated and at the moment it will take huge time to generate a vector graphic for my PNG Icon, so how do i proceed with this? – Sri Krishna May 16 '18 at 12:02