Adaptive icon for Android with old Unity

FIFTYTWO
2 min readSep 22, 2018

--

by Dmitry Victorov

With Android API level 26 we got new feature — adaptive icons. Having this new feature we have a problem with old Unity versions because they don’t make adaptive icons automatically. Unity introduced adaptive icons support in 2018.1. As I read on forum, earlier Unity versions such as 2017 will not support adaptive icons in future patches. But there is a way to embed adaptive icon as part of regular build pipeline.

I’ll tell about adaptive icons in some words. You can read full article about them at android developers page. Adaptive icon consists of 2 layers: background and foreground. Foreground layer may have transparent areas. So the device may apply shape mask and move foreground layer relative to background for interesting visual effects such as parallax. Both layers must be 108x108 dp in total size and you should keep in mind that main visible center area will be 72x72 dp. DPs are density independent pixels, you can convert them to usual pixels with this tool for example.

Examle of adaptive icon building

Let’s export Gradle project from Unity 2017 and 2018 to compare them. 2017 has icon record in manifest android:icon=”@drawable/app_icon” and 2018 has android:icon=”@mipmap/app_icon”. Looking at resources we see all those folders with icons and notice 2018 has 4 icons for each resolution: app_icon.png, app_icon_round.png, ic_launcher_background.png and ic_launcher_foreground.png. Also it has mipmap-anydpi-v26 with xml files describing adaptive icons for API level 26 and newer.

<?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>

So, it’s great thing that we don’t need to modify manifest and just need to extend our resources using “drawable” notation instead of “mipmap” notation.

Now the steps to achieve the goal:

  1. Create an empty project with Unity 2018.1 or newer and assign your android icon there including adaptive icon.
  2. Go to Android build settings, choose Build system: Gradle, check Export Project and export the project to some location.
  3. Go to exported Gradle project folder and open “src/main/res”.
  4. Rename all folders starting with mipmap-* to drawable-*
  5. Go to drawable-anydpi-v26 and replace @mipmap to @drawable in files app_icon.xml and app_icon_round.xml
  6. Go to your original project made with old Unity
  7. Create folder “Assets/Plugins/Android/res”
  8. Copy all drawable-* folders from above Gradle project to just created “Assets/Plugins/Android/res”
  9. Finally your project must have the following folders:
    Assets/Plugins/Android/res/drawable-anydpi-v26
    Assets/Plugins/Android/res/drawable-hdpi
    Assets/Plugins/Android/res/drawable-ldpi
    Assets/Plugins/Android/res/drawable-mdpi
    Assets/Plugins/Android/res/drawable-xhdpi
    Assets/Plugins/Android/res/drawable-xxhdpi
    Assets/Plugins/Android/res/drawable-xxxhdpi

That’s all! Now every time you build Android target it’ll have adaptive icon embeddeded automatically. The only annoying thing — you’ll have to repeat those steps each time you decide to change the app icon.

--

--

FIFTYTWO

Creators of Kenshō & JELLIES! Writing about game development, design & code. Learn about us: www.wefiftytwo.com