weixin_39732027
weixin_39732027
2021-01-07 11:04

exclude roboto font

carbon is a very cool lib materialized my app with almost no extra work. but it has a side-effect that roboto fonts which i don't use in my language inceased the size of apk by 2mb. I was wondering if there's a way to remove roboto fonts from carbon lib?

该提问来源于开源项目:ZieIony/Carbon

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

9条回答

  • weixin_39700397 weixin_39700397 3月前

    I have to think about it. Basically Carbon was intended to work on Android 2.2 which is main target of my other app. Android 2.2 doesn't have Roboto, so I need it. But, I'm aware of that Roboto is present on newer systems. Maybe providing Roboto as an opt-in package would be good. The other option is to remove these files with Proguard.

    点赞 评论 复制链接分享
  • weixin_39732027 weixin_39732027 3月前

    I tried with proguard setting minifyEnabled to true but it doesn't seems to help. also with shrinkResources true

    点赞 评论 复制链接分享
  • weixin_39700397 weixin_39700397 3月前

    This issue was raised before with no real solution except cloning the repo and removing fonts manually. See: https://github.com/ZieIony/Carbon/issues/154

    I have to check if it's safe to remove fonts. Ideally removing fonts on ICS and above should work fine.

    点赞 评论 复制链接分享
  • weixin_39700397 weixin_39700397 3月前

    Let's keep this issue open until we find a better solution.

    点赞 评论 复制链接分享
  • weixin_39572764 weixin_39572764 3月前

    What if just completely remove the fonts from library package? Roboto font is free for downloading from Material Design guidelines site so anyone can get particular typefaces from the whole font archive and use them. Am I wrong?

    点赞 评论 复制链接分享
  • weixin_39700397 weixin_39700397 3月前

    You're right, but: 1. Fonts have to be in assets/fonts and have correct names. I'm sure that someone will forget about that and report not working fonts as a bug. Or will ask where he/she can find these fonts. I would like to have a more straightforward solution. 2. I'm not sure what happens when you just delete fonts. Probably it won't work on newer Androids because there's no code for using system fonts if present. 3. It's not as important as 1 and 2, but Roboto was updated recently, so only Lollipop and Marshmallow have the correct version. See: https://www.google.com/fonts/specimen/Roboto

    点赞 评论 复制链接分享
  • weixin_39572764 weixin_39572764 3月前
    1. I thought that using custom fonts from assets folder is a common task and Carbon just makes it easier. I mean using fonts from assets folder of app itself and not library's.
    2. Custom fonts can be used on any Android OS, so it seems to be a good solution for me.
    点赞 评论 复制链接分享
  • weixin_39700397 weixin_39700397 3月前

    Carbon contains these fonts, because carbon_Theme makes heavy use of them. I just wanted to have Roboto on all platforms and all views by default. That's why I need a specific set of correct files.

    http://stackoverflow.com/questions/12128331/how-to-change-fontfamily-of-textview-in-android

    Probably the best approach would be to extend android:fontFamily and android:textStyle to be translated to Roboto on all platforms (Roboto Thin working pre 4.2, etc.). The assets folder with all fonts can be moved to a different place, so users can download it right from Carbon's repository when needed. The carbon_fontPath attribute can stay as it is now.

    点赞 评论 复制链接分享
  • weixin_39700397 weixin_39700397 3月前

    Done. Now to get all fonts on all platforms you have to download .ttf files to your project. See samples.

    点赞 评论 复制链接分享