Legacy icon does not show when using adaptive icon - android

I just converted my app icon to be compatible with android o's adaptive icons using the Image Asset Studio in android studio
when I run my project now on my device running API 25 I get the default green android icon and not my icon.
this is my manifest
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:allowBackup="false"
android:roundIcon="#mipmap/ic_launcher_round"
tools:replace="allowBackup"
tools:ignore="GoogleAppIndexingWarning">
and these are the files the image asset studio created
Is this just an Android Studio bug or did I miss something?

I had the same trouble, and solved it by renaming my mipmap-anydpi directory to mipmap-anydpi-v26.
Apparently the ic_launcher.xml file confuses older Android versions, and this hides it from all but O. At any rate, my icons now work on all versions (down to SDK 11, at least).

Solution is to have mipmap-anydpi-v26/ic_launcher.xml for adaptive icons applicable for API level 26 and above and for other API levels put ic_launcher.png (Note: Not ic_launcher.xml) in all mimpap folders.
Explanation:
Here is the basic problem mipmap-anydpi take precedence over all other mipmap-*. So if resource is found in mipmap-anydpi it will always take preference. Now mipmap-anydpi-v26 is a filter above this which says resources from mipmap-anydpi-v26 will always be picked irrespective of devices density only if API level is 26 or more (Oreo).
Now you manifest has android:icon="#mipmap/ic_launcher"
If your device has API level 26 or above android will choose to use mipmap-anydpi-v26/ic_launcher.xml and everything works fine.
The problem happens when API level is less than 26. Android stats looking for resource named ic_launcher. It will never go and search in mipmap-anydpi-v26 because of API level constraint. Next, it would look for the resource in mipmap-anydpi and if not there then the actual density resource Eg. mipmap-mdpi.
Next, you cannot give ic_launcher.xml to android devices less than sdk 26 because it does not know what adaptive icons is.
So the solution is to have mipmap-anydpi-v26/ic_launcher.xml for adaptive icons applicable for API level 26 and above and for other API levels put ic_launcher.png (Note: Not ic_launcher.xml) in all mimpap folders.

I have been faced same issue and resolved as below.
Put your ic_launcher.xml and ic_launcher_round.xml should be in mipmap-anydpi-v26 (make sure you should not have ic_launcher.png/jpg or ic_launcher_round.png/jpg in same folder).
Put your ic_launcher.png should be in mipmap-hdpi/mdpi/xhdpi/xxhdpi/xxxhdpi (make sure you should not have ic_launcher.xml and ic_launcher_round.xml in these same folder).
By doing this, You will not get any errors building/running project.
Hope it helps some one who are same issue...

If still not working, check your XML schmema in , if you use auto import from Android studio, it will not work, it should be /apk/res/android. Here is the code:
<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>

I will conclude this in a very simple manner.
I used android studio just to generate the sources (background and foreground layers of images) which is used in my config.xml file.
So it will look like this :-
<icon background="resources/android/icon/ldpi_background.png" density="ldpi" foreground="resources/android/icon/ldpi_foreground.png">
The above configuration will work well with Android API level > 25.
Here comes the main problem for legacy icon in old versions of android
As per cordova official documentation - adaptive icons are not supported in old versions of android - and with above config.xml it will pick foreground part only as a fallback icon which is the reason your icon doesn't look nice in old versions.
So i applied the following fix for that ( as per cordova official documentation)
Add the src attribute with static image icons - so in old versions instead of using the fallback icon it will use that icon and for latest versions it will give priority to adaptive icons and hence problem will be solved for both.
config will look like this after the fix :-
<icon background="resources/android/icon/ldpi_background.png" density="ldpi" foreground="resources/android/icon/ldpi_foreground.png" src="resources/android/icon/drawable-ldpi-icon.png"/>

Related

Android Gradle v 3.1.3 update turned app launcher icon to default

After I updated my build.gradle with
com.android.tools.build:gradle:3.1.3
The icon of my app shows up as default android Icon.
I am using correct icon and round icon in my AndroidManifest.xml as below
<application
android:name=".EbatesApp"
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/application_name"
android:resizeableActivity="false"
android:roundIcon="#mipmap/ic_launcher_circle"
android:supportsRtl="false"
android:theme="#style/AppTheme"
tools:replace="android:allowBackup,android:supportsRtl,label"
>
I have mipmap-anydpi that has ic_launcher.xml and ic_launcher_circle.xml
And that subsequently calls appropriate pngs from mipmap folders based on resolution.
This works only for the devices that has Android O+.
All this was working fine till gradle v 2.3.3. However after update this doesn't seem to work.
I have searched on SO and found similar post App icon doesn't show (Android Studio) , but that doesn't work for me.
No word on it in migrartion guide either: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration
Any inputs on what seems to missing would be greatly appriciated
This is actually the same as this post:
Application icon not showing after Gradle plugin update to 3.0
This is not specific to v3.1.3, but v3.0.0 in general. The solution is to change from mipmap-anydpi -> mipmap-anydpi-v26.

Getting errors after copying existing project files into a new AndroidStudio Android project

I was able to create a new project In Android Stdio which ran fine.
Then I copied many of the files from an old project into it, and tried to run it, but I got this error about AppTheme:
It talks about values-v21.xml which I didn't have before. What is that file? And how can I get around this issue?
Thanks!
In your Manifest file. Change,
android:theme="#style/AppTheme"
To,
android:theme="#style/AppBaseTheme"
I think the problem is the file name. Your file is named "values-v21.xml", all the android projects I saw had that file name as "styles.xml" and was included inside the v21 folder. Also I included an image. Sorry for the poor resolution.
Also, v21 means that it's for API Level 21 and above. API Level 21 is Android 5.0 (Lollipop). For more info on API Level 21: http://developer.android.com/about/versions/android-5.0.html
I hope this fixes your problem.

Enable android:largeHeap in Android 4, and disable it in Android 2.3

Currently, I have a piece of code, which is designed to run both in Android 2.3 and 4+
The code will perform much better (Where it will not have OutOfMemory exception most of the time), if android:largeHeap is being applied in AndroidManifest.xml.
<application
android:name=".MyApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:screenOrientation="nosensor"
android:largeHeap="true"
Currently, my android:minSdkVersion need to set to 15 instead of 10 (Android 2.3). If not, android:largeHeap is not allowable in AndroidManifest.xml.
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
Within single APK, how possible I can set
Use android:largeHeap option if I were in Android 4+
Do not use android:largeHeap option if I were in Android 2.3
You can also disable large heap in Honeycomb and enable it in ICS or JB. Just a little hacky or something. Here's what I tried.
Before we proceed, change your Build target to Honeycomb, Jelly Bean or ICS so we can put android:largeHeap attribute. Also, you can set android:minSdkVersion to API 10.
Android API 10 doesn't support large heap.
Create a folder values-v14 in res folder
I created bools.xml in values-v14
Put this value in bools.xml of values-v14
<bool name="largeheap">true</bool>
boolean value for values > bools.xml or values-[API VERSION] > bools.xml to disable large-heap in different API Version or by default.
<bool name="largeheap">false</bool>
Change the value of android:largeHeap to #bool/largeheap instead of hardcoded true or false
<application
android:largeHeap="#bool/largeheap"
android:allowBackup="true"
android:icon="#drawable/ic_launcher">
....
</application>
I tested this code by making a memory leak application or just load a Huge bitmaps, and, its working!
Good Luck!
Keep the android:largeHeap="true" attribute in your AndroidManifest.xml. This should be ignored for versions that don't support it. Then, to support older versions, set the heap size using the VMRuntime class (via reflection, if necessary).
More on this topic: How to increase heap size of an android application?
1.Build project with target Android 3.0 (API 11) or above.
(Project properties - Android - Project Build Target - select above API level 11)
in Manifest file, Change the uses-sdk value as following
< uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="11" />
For prior versions of Android 3.0, you can use VMRuntime class for memory manipulations.
Seems that you have incorrect target sdk in project.properties file, check it out and change target to your AndroidManifest`s targetSdk (15) and rebuild project.
project.properties
# Project target.
target=15
P.S. I tryed add android:largeHeap to my Project (minSdk = 7, targetSdk = 17) compiled and run normally on all Android versions.
Please change project properties:
In project Properties -> Android -> Project Build Target -> Google API, API level 19 (or any other you need) :)
So your can leave your minimum SDK option without change, for example 8 :)

Android XML Style/Theme Version Compatibility, Considering Development Safety with Eclipse/lint

It appears the best way to develop an Android application today is to target android-17 in project.properties along with minSdkVersion "whateversuitsyou" and targetSdkVersion 17 in the manifest.
In this configuration, the standard lint checks will notify about any API calls which are only available in API versions above "whateversuitsyou" and one can use reflection etc to dynamically support the newer features, if any.
However, in this setup, at least without further configuration, it is possible to have style and theme attributes in XML not placed in the appropriate folder, like referring to "Holo" elements in the default resource folder when "whateversuitsyou" is smaller than 11 aka Honeycomb.
It seems apps will not crash if they encounter unknown XML style attributes. LogCat will show an error, like "Style contains key with bad entry".
Not sure whether the whole style is checked upon app startup; if so, it is certainly possible to run the app once on every API version to check for any problems. However, that's not exactly desirable. Besides, styles and themes are not the only version specific resources.
Is there a way to make lint check the resources in general against minSdkVersion and API versio XY for folder *-vXY? Can someone shed some light on this?
Luckily, with the current (updated) configuration, this has become a non-issue, because the development framework handles the situation just the way it should.
Example:
project.properties:
target=android-11
AndroidManifest.xml:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
You can now use API 8 XML style and theme attributes everywhere and API 11 XML style and theme attributes in -v11 subfolders.
Works with Eclipse Juno Service Release 1, Android SDK Tools 21.1 and Android SDK Platform-tools 16.0.1.

adding android:widgetCategory="keyguard|home_screen" while still supporting older sdk

I am trying to modify my widget so that it supports being placed on 4.2 lockscreens. However I still want to support older SDK's.
I added
android:widgetCategory="keyguard|home_screen"
to my appwidget-provider in res/xml, but eclipse complains that there is "no resource identifier found for attribute widetCategory in package android'
If I raise the minSdkVerion to 17 everything works fine, but I want to still support older SDKs.
I have tried using resource qualifiers creating a separte res/xml-v17/mywidget.xml and only adding the tag there, but the error still appears.
Thanks for any help.
Edit:
I figured it out. using a res/xml-v17/ folder is the answer. I just had to change the build target for my project to 17 / 4.2.
I think that setting targetSdk to 17 is enough. XML elements that do not make sense on older SDKs are simply ignored.
No need to put mywidget.xml into res/xml-v17 folder
Put a copy of your mywidget.xml in res/xml-v17/ folder.
This targets Android 4.2 and all new "properties on the appwidget-provider element will be avaible. Also right click your project in eclipse and change build target to: API level 17/ Android 4.2
I saw your Edit. But i think this makes it more clear that this question have an answer.
UPDATE: I can confirm Tomáš Hubálek answer. the xml-v17 is not needed. Changing Build target is enough. Right click your project in eclipse and change build target to: API level 17/ Android 4.2

Categories

Resources