Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Asset NOT generating ic_launcher_foreground.xml file

Tags:

I have created all my adaptive icons in the Image Asset tool but its not creating the ic_launcher_foreground.xml file - which in turn is causing my build to fail because the foreground.xml file is being referenced in the ic_launcher.xml and ic_launcher_round.xml files.

I have read many threads on how to resolve this but none of them are working.

As well, both ic_launcher.xml and ic_launcher_round.xml files are specifically referencing these two files:

<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@mipmap/ic_launcher_foreground" />

The /drawable folder is being created with the ic_launcher_background.xml file, but the Image Asset tool is not creating a /mipmap folder - it looks to be creating all the other /mipmap-XYZdpi folders and icons.

I bring this up because alot of other threads show the ic_launcher.xml and ic_launcher_round.xml files reference both background.xml and foreground.xml files in the same /drawable folder, unlike mine above.

In Image Asset: Foreground Tab: Layer Name: ic_launcher_foreground Asset Type: image Path: /dev/myApp/resources/myCustomIcon.png Background Tab: Layer Name: ic_launcher_background Asset Type: image Path: res/drawable/ic_launcher_background.xml

The only time I can get the ic_launcher_foreground.xml file to appear in the "Output Files" screen is if on the foreground tab I select Asset Type: Clip Art

UPDATE:

I found a ic_launcher_foreground.xml file in a drawable (v24) folder deep in an Android Studio folder related to my project. I copied that file to my projects res/drawable folder - and now I get the Android half robot Icon for my app when it compiles to my test device.

like image 420
rolinger Avatar asked Apr 18 '20 14:04

rolinger


1 Answers

Well, I figured this out - finally. Posting my answer for anyone else that has the same issues.

Using Image Asset tool - ic_launcher_foreground.xml and ic_launcher_background.xml will ONLY be generated if each type (foreground tab/background tab) Asset Type is defined as anything BUT an image type. PNG/JPG asset types do not generate these xml files.

Regardless of Asset Types, both ic_launcher.xml and ic_launcher_round.xml WILL be generated. Both of these xml files simply reference other files, if Asset type is color/art/text - the reference will be to other XML files that will either be in the @drawable/ folder or the @values/ folder.

<background android:drawable="@drawable/ic_launcher_background" /> OR 
<background android:drawable="@values/ic_launcher_background" /> 
//@drawable - is the root of all your drawables folders
//   - and references only XML, ie: ie_launcher_background.xml

If the Asset Type is an image (png/jpg) then the reference will be to the newly created png/jpg files that exist in any of the @mipmap folders.

<foreground android:drawable="@mipmap/ic_launcher_foreground" />
// @mipmap is simply root of all your mipmap folders
// references actual png files, ie: ic_launcher_foreground.png

And finally, if you are using Cordova, you need to modify your config.xml to reflect the icon FILES to use:

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
     <application android:icon="@mipmap/ic_launcher"  android:roundIcon="@mipmap/ic_launcher_round" />
</edit-config>
// this telling the app to find those two XML files in the mipmap-anydpi-v26 folder
// and those files in turn tell the app to find all the png files in the other "mipmap" folders

// if it were this:
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
     <application android:icon="@drawable/ic_launcher"  android:roundIcon="@drawable/ic_launcher_round" />
</edit-config>
// this telling the app to use the XML files sourced in the drawable folders
// if you used png as foreground and color as background
// ic_launcher.xml/ic_launcher_round.xml would both point to:
//      @mipmap/ic_launcher_foreground   (ie: png images)
//      @drawable/ic_launcher_background  (ie: xml files)

I hope this helps others as I feel all of the above is poorly explained in other documentation.

like image 135
rolinger Avatar answered Oct 01 '22 01:10

rolinger