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.
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.
It is very simple now: start "Image Asset Studio" by Right clicking on the "res" or "mipmap" folder and select "New > Image Asset" from the pop-up menu. Image Asset Studio will now open. Now you can create an Adaptive Launcher Icon or Legacy Only Launcher Icon as per your requirements.
To update and existing icon just select your existing ic_launcher_foreground.xml file and ic_launcher_background.xml file and hit "Next" to create the new definitions, overwriting the old ones.
With Windows Explorer go to your project "res" folder where all "ic_launcher files" are stored and delete all "ic_launcher files" first
Now in Android Studio "click on mipmap folder"->"Generate image asset".
It solved the issue for me
Well, what I did... (It often happens that others' solutions who say they finally fixed it never work for me, so I thought I would contribute yet another solution that might only work for me :) )
First I generated the image assets file as-is. I right-clicked on the res folder, clicked "New", then "Image asset". I left the "source asset" path as-is (with the path to the launcher_foreground.xml file in place) and created the assets.
Then I went back and generated the image assets again, but this time with my own png image. Seems to have worked so far, at least until the next update makes this solution obsolete.
On the second page of the asset studio wizard, there is a dropdown called "Res Directory".
I had to select debug before clicking finish. I was able to build after that.
Open your Android Studio and go to your project then
go to android-> app -> scr -> main -> res -> mipmap-anydpi-v26 on
Right click -> New -> image Asset -> Configure image asset -> path ->
mipmap-hdpi -> ic_launcher_foreground.png
Following these steps will solve your problem definitely.
Related
I've been searching for several days now a way to embed a data file, which is in text format, inside an app I'm trying to build in Adobe Flash for Adobe Air (for Android for now). The text file has a lot of data I want to use in my app, so I want to embed it inside the app, so when the app launches I can use it.
I've been reading about how to read and write text file in Flash and Adobe Air, but couldn't find a way to add this file to be part of my app. The Adobe Flash Library that is used for saving various assert (File > Import > Import to Library), doesn't support text file (only image, sound, video, and other graphic formats). Is there an other way to add a different (i.e. Text) file to the app?
As a last resort, and to help me proceed with the implementation, I tried manually copying the file to the Android "Documents" folder, and reading it from the app using this:
var myFile:File = File.documentsDirectory.resolvePath("MyText.txt");
var fileStream:FileStream = new FileStream();
fileStream.open(myFile, FileMode.READ);
var fileContents:String = fileStream.readUTFBytes(fileStream.bytesAvailable);
This worked on the PC when testing, but on Android it couldn't find my text file. I placed it in "My Files > Internal storage > Documents" (on Samsung phone). Is there a different "Documents" folder I should use to be found by documentsDirectory.resolvePath() function...
Anyway, as said, this was last resort solution, and much less preferred, because I don't want the users of my app to need to copy internal data files for the app to work, it should be part of the APK... So embedding the text file somehow inside the app is a much better solution, but I couldn't find a way to do that.
Thanks Organis for your answer, I didn't yet try it but I guess it should work.
I found another answer few hours ago, and will share it now, in case someone else encounters this problem.
You could embed a file from the "Publish Settings" dialog, then going into "AIR for Android Setting" (small wrench icon). On the "AIR for Android Setting" under "General" tab, at the bottom there is "Include files". You can click the [+] icon and add any file you want.
From the code you can access this file using standard file read method, using URLLoader & URLRequest functions and Event.COMPLETE to get the data when the file finishes loading.
see screenshot here
I create a Xamarin Forms project in VS 2017 and started by adding a TabbedPage with three tabs. I then added the icons to the Android (in Resources/drawable) and iOS (Asset Catalogs/Icons) projects.
When I start the project on Android it works fine, but on iOS I get an exception that the UIImage cannot be loaded because initWithCOntentsOfFile returned nil. Which is actually correct, because that's not the correct method to use to access Assets. But it's the TabbedPage calling the method, so I cannot do anything about it.
The TabbetPage looks pretty basic.
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:GreenThumb"
x:Class="GreenThumb.MainPage">
<NavigationPage Title="Today" Icon="current.png">
<x:Arguments>
<local:Current />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Overview" Icon="overview.png">
<x:Arguments>
<local:Overview />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Settings" Icon="settings.png">
<x:Arguments>
<local:Settings />
</x:Arguments>
</NavigationPage>
</TabbedPage>
And the Asset Catalog looks like this:
This problem seems to be pretty old, but I haven't found any solutions aside some very dirty hacks.
Is there a clean solution out there? Or do I just have to add all my images in the Resources folder instead of Asset Catalogs?
I struggled in the past on this issue. It seems that icons for tabbed pages are not working in iOS if placed in the .xcassets.
I moved those .png files inside the Resources folder and that made the magic.
I suppose it's a kind of bug on Xamarin.
The same error was occurring to me, and I was putting the images on the .xcassets on iOS.
When I placed the images on the Resources folder, they appeared normally on my TabbedPage.
In the official Xamarin documentation about images, they say to put the images in the Resources folder.
iOS - Place images in the Resources folder with Build Action:
BundleResource. Retina versions of the image should also be supplied -
two and three times the resolution with a #2x or #3x suffixes on the
filename before the file extension (eg. myimage#2x.png).
I place all my images in the .xcassets folder, they apparently work well, but it seems not to work on every case.
I'm designing my layout, and I've exported many assets from Sketch. Everything's going fine, but on just one particular asset, I'm getting the following error:
The resource is there, included in the project, I can open it (a regular PNG) perfectly etc, and is no different from any other assets in any way.
When I click Details on the error above, I get:
java.lang.NumberFormatException: Color value '#drawable/comment_off' must start with #
at com.android.layoutlib.bridge.impl.ResourceHelper.getColor(ResourceHelper.java:79)
at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:270)
at android.content.res.BridgeTypedArray.getDrawable(BridgeTypedArray.java:729)
at android.widget.ImageView.<init>(ImageView.java:152)
at android.widget.ImageView.<init>(ImageView.java:140)
at android.widget.ImageView.<init>(ImageView.java:136)
...
Why on Earth does Android Studio think that my drawable is a color, while it's a PNG image like all the other assets in my project?
You may want to check the spelling of your drawable folder to ensure it is correct, and that the image exists at the referenced assets folder.
I tried to add embed = true in project xml like this:
<assets embed="true" path="Assets" rename="assets" include="*" exclude="openfl.svg" />
But if I try to delete an image from assets folder, then run the exe file, the image will not be displayed, thus, it still loaded form assets folder.
Can some one help?
Thanks every body, I found the answer of Joshua here Embeding and reading image assets when deploying to Windows
But who to know where to read about the answer in the openFL documentation?
Since the latest versions of Apportable the app icon of my app appears too small in the Android launcher (half the size of other apps' icons).
I tried to set the "ICON" property in configuration.json file but could not make it work.
"ICON": "./Icon.png",
What is the reference folder here?
I have the usual Icon-*.png files in the /Resources folder of my Obj-C code (the largest one being Icon-72#2x.png). Can I directly point to one of them ? Or do I need to copy the desired icon into the .approj folder?
File references in the configuration.json are relative to the folder that includes the .xcodeproj file.
Finally it seems that the reference folder is the "root" of the project, i.e the folder containing the .approj folder.
So in my case the following worked just fine:
"ICON": "./<app>/Resources/Icon-72#2x.png",