badge icon indicating copy to clipboard operation
badge copied to clipboard

Cannot add badge on Android 8 and 9

Open NinjaRat84 opened this issue 6 years ago • 19 comments

Hi,

Badge does not seems to be added on versions 8 and 9 for Android which uses vector icons as ic_launcher_foreground and ic_launcher_background.

Should this be a future enhancement?

Best regards, H

NinjaRat84 avatar Sep 07 '18 07:09 NinjaRat84

+1

Paul-McNeice avatar Oct 08 '18 12:10 Paul-McNeice

+1

madyx avatar Oct 10 '18 14:10 madyx

+1

Can you please provide a bit more info to this issue. What file format is it? It should support SVG, maybe to fix is a simple one.

HazAT avatar Nov 27 '18 20:11 HazAT

@HazAT They're Android vector drawable resources - the files are XML files.

Here's the Android documentation that explains about Adaptive Icons on Android 8: https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive

Here's an example of a vector resource:

<!-- res/drawable/battery_charging.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    <!-- intrinsic size of the drawable -->
    android:height="24dp"
    android:width="24dp"
    <!-- size of the virtual canvas -->
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">
   <group
         android:name="rotationGroup"
         android:pivotX="10.0"
         android:pivotY="10.0"
         android:rotation="15.0" >
      <path
        android:name="vect"
        android:fillColor="#FF000000"
        android:pathData="M15.67,4H14V2h-4v2H8.33C7.6,4 7,4.6 7,5.33V9h4.93L13,7v2h4V5.33C17,4.6 16.4,4 15.67,4z"
        android:fillAlpha=".3"/>
      <path
        android:name="draw"
        android:fillColor="#FF000000"
        android:pathData="M13,12.5h2L11,20v-5.5H9L11.93,9H7v11.67C7,21.4 7.6,22 8.33,22h7.33c0.74,0 1.34,-0.6 1.34,-1.33V9h-4v3.5z"/>
   </group>
</vector>

Which was taken from this page: https://developer.android.com/guide/topics/graphics/vector-drawable-resources

Android doesn't support displaying SVG files out of the box, so when we want to use vector assets we import an SVG and it gets converted into the format above

Paul-McNeice avatar Nov 28 '18 08:11 Paul-McNeice

I have the same issue.

I'm trying to support Adaptive icons on Android. In adaptive icons, there are different launcher icons are generated. so, I am trying to add badge and shield to all of them like below code snippet :

badge(glob: "/app/src/main/res/mipmap-*/ic_launcher.png",
    shield: "105", # versionCode of android app
    shield_gravity: "NorthWest",
    shield_no_resize: true
)

badge(glob: "/app/src/main/res/mipmap-*/ic_launcher_foreground.png",
    shield: "105", # versionCode of android app
    shield_gravity: "NorthWest",
    shield_no_resize: true
)

badge(glob: "/app/src/main/res/mipmap-*/ic_launcher_round.png",
    shield: "105", # versionCode of android app
    shield_gravity: "NorthWest",
    shield_no_resize: true
)

Badge is looking okay but shield ( I am using shield for build number ) does not seem on adaptive icons. I need to add something like shield_geometry "+0+25%" but it does not work.

as per documentation : https://github.com/HazAT/badge#--6

When I use shield_geometry on fastlane like this :

badge(glob: "/app/src/main/res/mipmap-*/ic_launcher_round.png",
    shield: "105", # versionCode of android app
    shield_gravity: "NorthWest",
    shield_no_resize: true,
    shield_geometry: "+0+25%"
)

it procudes this error :

fastlane finished with errors

[!] Could not find option 'shield_geometry' in the list of available options: dark, custom, no_badge, shield, alpha, path, shield_io_timeout, glob, alpha_channel, shield_gravity, shield_no_resize

okarakose avatar Feb 07 '19 10:02 okarakose

+1

futabooo avatar Sep 02 '19 04:09 futabooo

It doesn't work for me even if I badge for ic_launcher.png, ic_launcher_foreground.png and ic_launcher_round.png. On older version of android it works like a charm.

czater avatar Nov 07 '19 10:11 czater

Here is my configuration. Hoping it would help anyone out:

    badge(
      shield: "BETA-0.0.1-orange", 
      no_badge: true,
      dark: true,
      shield_scale: "0.55",
      shield_gravity: "Center",
      shield_geometry: "+0+30%",
      glob: "/app/src/main/res/mipmap-*/ic_launcher*.png",
    )

Output

Android Studio

On Android 9 phone

screenshot

osamaqarem avatar Mar 10 '20 07:03 osamaqarem

I'd love to see this fixed. Does anyone have ideas on what needs to be done?

gwmccull avatar Apr 08 '20 00:04 gwmccull

I suspect the problem with later Android versions is that the plugin doesn't support badging of adaptive icons.

Either that would need to be done or, as a workaround, you could remove the adaptive icon files in your badged builds and later versions of Android would then fall back to using the legacy launcher icon instead (which is badged)

liamjones avatar Apr 08 '20 07:04 liamjones

This is what I finally did after reading conflicting reports of badging partially working on adaptive icons. I suspect all of those reports were from people testing pre-8 devices or did not have adaptive icons setup properly. I ended, copying the mipmaps to the res/<ProductFlavor> directory for our staging flavor, and only using the adaptive icon format for production.

hyei avatar Apr 10 '20 16:04 hyei

@hyei thanks, I'll take a look at that

gwmccull avatar Apr 10 '20 17:04 gwmccull

@osamaq wonderful!. The glob: "/app/src/main/res/mipmap-*/ic_launcher*.png", works with fastlane even when real directory would be "../app/src/main/res/mipmap-*/ic_launcher*.png"

isaac-tribal avatar Dec 08 '20 21:12 isaac-tribal

I can see the icons updating with shield values config and version at locations src/main/res & src/debug/res, After build and installed the app, I can see the shield values on app icon for android 7 and doesn't see them in Android (>= 8). May I know is there any update on this.

plugin version used: fastlane-plugin-badge 1.4.0 lane :android_shield do |options| add_badge( shield: "#{ENV['CONFIG']}-#{ENV['VERSION']}-green", no_badge: true, glob: "/app/src/**/mipmap-*/launcher_icon.png", shield_scale: "0.90" ) end

harasai avatar Jan 11 '21 04:01 harasai

@harasai see my comment above, the plugin doesn't badge adaptive icons (probably in your project as ic_launcher*.xml)

liamjones avatar Jan 11 '21 08:01 liamjones

As workaround for adaptive icons i'm using only glob: "/app/src/main/ic_launcher-playstore.png" for creating badge. And then using it to create icons with New -> Image Asset option from Android Studio which generates all icons correctly

StanislavBondar avatar Jan 14 '21 10:01 StanislavBondar

I could not get the default badge reasonably positioned for both IOS and Android adaptive and Android legacy icons. So i created a new set of badges. For anyone who is interested

https://github.com/bobsmits/gem-badge-adaptive-icon-set/tree/main

bobsmits avatar Jan 14 '21 14:01 bobsmits

Here is my configuration. Hoping it would help anyone out:

    badge(
      shield: "BETA-0.0.1-orange", 
      no_badge: true,
      dark: true,
      shield_scale: "0.55",
      shield_gravity: "Center",
      shield_geometry: "+0+30%",
      glob: "/app/src/main/res/mipmap-*/ic_launcher*.png",
    )

Using this glob configuration, all mipmap launchers in the .png format were badged correctly.

I then moved all adaptive launcher icons (*.xml) to the prod source set, which resulted in Android falling back onto the badged icons for non-prod builds.

Unfortunately, that way, Samsung (and probably other) phones will squeeze the icon into their adaptive form. The badge is still readable, but it is not beautiful. However, it may still be useful to some of you as a workaround.

zie-marco avatar Apr 26 '21 13:04 zie-marco