Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add badge on Android 8 and 9 #77

Open
NinjaRat84 opened this issue Sep 7, 2018 · 19 comments
Open

Cannot add badge on Android 8 and 9 #77

NinjaRat84 opened this issue Sep 7, 2018 · 19 comments

Comments

@NinjaRat84
Copy link

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

@Paul-McNeice
Copy link

+1

2 similar comments
@madyx
Copy link

madyx commented Oct 10, 2018

+1

@MuthukathiravanMurugasan

+1

@HazAT
Copy link
Owner

HazAT commented Nov 27, 2018

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.

@Paul-McNeice
Copy link

Paul-McNeice commented Nov 28, 2018

@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

@okarakose
Copy link

okarakose commented Feb 7, 2019

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

@futabooo
Copy link

futabooo commented Sep 2, 2019

+1

@czater
Copy link

czater commented Nov 7, 2019

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.

@osamaqarem
Copy link

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

@gwmccull
Copy link

gwmccull commented Apr 8, 2020

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

@liamjones
Copy link

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)

@hyei
Copy link

hyei commented Apr 10, 2020

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/ directory for our staging flavor, and only using the adaptive icon format for production.

@gwmccull
Copy link

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

@isaac-tribal
Copy link

@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"

@harasai
Copy link

harasai commented Jan 11, 2021

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

@liamjones
Copy link

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

@StanislavBondar
Copy link

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

@bobsmits
Copy link

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

@zie-marco
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests