16

manifest:

<application
    android:name="..."
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/MyTheme"
    tools:replace="icon,label,theme,name,allowBackup">

under the folder mipmap-anydpi-v26 I have defined ic_launcher.xml:

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

here is my folder structure : enter image description here

build.gradle:

compileSdkVersion = 26
buildToolsVersion = "25.0.2"
supportLibVersion = "25.3.1"
targetSdkVersion = 25
minSdkVersion = 18

AND, I'm using android studio 3.0

but the end result is that I get a default android icon instead of the one I provided.

I've also tried putting the foreground png in all of the density folders (mipmap-xhdpi, etc), although I used the same png for all when I did this just for testing

Siavash
  • 7,583
  • 13
  • 49
  • 69

5 Answers5

11

Adaptive icon requied API 26 so you need to update your buildtools to at least 26.0.0 version

Karol Kulbaka
  • 1,136
  • 11
  • 21
  • Thank you, this was incredibly helpful – Marc Nov 03 '17 at 11:12
  • 12
    I have the build tools set to 26.0.2 but it still show the default icon. – Etienne Lawlor Nov 14 '17 at 06:56
  • 4
    In Android Studio go to Help -> "Find action..." type "image asset" and click to open it. In there you can specify the foreground image, the background image(or color) and it will automatically generate all the launcher images and xml files. – Cristi Feb 20 '18 at 15:00
  • @toobsco42 I had the same issue but it turned out to be because I mistakenly used the wrong xmls definition (basically I used what Android Studio suggested as the auto-fix, which was a bad idea in this case). – blunden May 06 '18 at 01:29
  • i dont see the requirements for the buildtools in the official documentation [https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive](https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive), where is this documented? – BluePie Aug 07 '19 at 05:41
  • okey i think I got it, for anyone else having this doubt refer [https://developer.android.com/studio/releases/build-tools.html](https://developer.android.com/studio/releases/build-tools.html) – BluePie Aug 07 '19 at 05:44
5

I too have faced the same issue, here is how I have fixed this issue

  1. Right click on resource -> New -> ImageAsset

  2. Choose the ic_launcher_background icon and ic_launcher_foreground as shown in below screen

enter image description here

  1. Android studio creates an ic_launcher.xml under resource mipmap (anydpi-v26)

     <?xml version="1.0" encoding="utf-8"?>
    <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>
    
  2. Now inside the Manifest.XML, declare the icon and round icon something shown in like below

    <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    
    
                    .......</application>
    

    Yes that's all and Run your app on any device it appears

Suresh Maidaragi
  • 2,173
  • 18
  • 25
  • Yep. I was using `drawable/ic_launcher` instead of `mipmap/ic_launcher`. Not use often and I think not well documented. – methodsignature Mar 13 '19 at 11:51
  • Somewhat yeah we need to dig more get in details, https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive – Suresh Maidaragi Mar 14 '19 at 04:11
  • Success. Yeah, if you replace your launcher icon you need to remember to replace your drawable for mipmap. This one got me good. – ZShock May 28 '20 at 01:43
2

I had issues getting my adaptive icon to display. Turns out I had done nothing wrong. It started working after I did a 'Clean Project' in Android Studio.

aaronmarino
  • 3,723
  • 1
  • 23
  • 36
0

ic_launcher.xml should be like this

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon
    xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/white"/>
    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Biki
  • 140
  • 1
  • 3
0

I tried to debug it using an <ImageView>. When I did so, I got a backtrace ending with:

Caused by: java.lang.IllegalArgumentException: Path string cannot be empty.

Turns out my ic_launcher_foreground.xml had some <path> elements with empty android:pathData attributes.

Deleting those empty <path>s made the icon work!

Mikel
  • 24,855
  • 8
  • 65
  • 66