GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Minify + Shrink resources removes String resources · Issue #331 · mikepenz/AboutLibraries

Minify + Shrink resources removes String resources #331

New issue
Copy link
New issue
Copy link
Closed
Closed
Minify + Shrink resources removes String resources#331
Copy link
Assignees
mikepenz
Labels
question

Description

@AllanWang
AllanWang
opened on Jul 8, 2017
Issue body actions

Obviously this is the case, and it can be fixed by keeping the R class, but I was wondering if there is hopefully a better alternative somehow. -keepresources looked promising but it seems to be a dexguard feature rather than a proguard feature.

In comparison, keeping all the R classes adds around 60kb to a < 3mb app, which is somewhat significant.

Activity

  1. rubengees commented on Jul 8, 2017

    @rubengees
    rubengees
    on Jul 8, 2017
    Contributor
    More actions

    I had success with this:

    -keepclasseswithmembers class **.R$* {
        public static final int define_*;
    }
    

    This only keeps the definitions used by AboutLibraries for autodetection but no other Strings.

    Reacted by Allan Wang and balalakshmi-s-3019
  2. mikepenz commented on Jul 8, 2017

    @mikepenz
    mikepenz
    on Jul 8, 2017
    Owner
    More actions

    @rubengees but wouldn't this also remove the strings of the libs themself? So do you add them manually to your project in addition?

  3. mikepenz
    self-assigned this
    on Jul 8, 2017
  4. mikepenz
    added
    question
    on Jul 8, 2017
  5. rubengees commented on Jul 8, 2017

    @rubengees
    rubengees
    on Jul 8, 2017
    Contributor
    More actions

    Hmm, no it works out of the box in my case. Maybe proguard intelligently recognizes the usage by the library? I do not use shrinkResources, but only proguard itself though.

  6. AllanWang commented on Jul 8, 2017

    @AllanWang
    AllanWang
    on Jul 8, 2017
    ContributorAuthor
    More actions

    Shrink resources is the issue, not proguard.
    I'm going to try what you have plus
    public static final int library_*; and see if that works

  7. mikepenz commented on Jul 8, 2017

    @mikepenz
    mikepenz
    on Jul 8, 2017
    Owner
    More actions

    It can't as those are loaded during the runtime. So this means your definition still keeps the resources.

    @AllanWang I do not think there is anything I can do about this, or the lib can do about it.

  8. rubengees commented on Jul 8, 2017

    @rubengees
    rubengees
    on Jul 8, 2017
    Contributor
    More actions

    Just tried it with shrinkResources enabled on my project, that works.

  9. AllanWang commented on Jul 8, 2017

    @AllanWang
    AllanWang
    on Jul 8, 2017
    ContributorAuthor
    More actions

    @rubengees is your project open sourced?

  10. AllanWang commented on Jul 8, 2017

    @AllanWang
    AllanWang
    on Jul 8, 2017
    ContributorAuthor
    More actions

    Also since this keeps the whole R class, I'm not sure if this will be better than the original rules

  11. rubengees commented on Jul 8, 2017

    @rubengees
    rubengees
    on Jul 8, 2017
    Contributor
    More actions

    Yes, here here are the proguard rules: https://github.com/proxer/ProxerAndroid/blob/master/app/proguard-rules.pro

    Also since this keeps the whole R class, I'm not sure if this will be better than the original rules

    I am not a proguard expert so this may be true. It did help me avoid the 65k field reference limit though, which popped up due to another lib (I only had the rule to keep entire R from the README before).

    @mikepenz

    It can't as those are loaded during the runtime.

    As far as I know, proguard is able to recognize patterns of Strings when using reflection and keeps those in the resources. If that is the case, I do not know, why the define_ statements does not get keeped...

  12. rubengees commented on Jul 8, 2017

    @rubengees
    rubengees
    on Jul 8, 2017
    Contributor
    More actions

    @AllanWang

    From the proguard documentation:

    -keepclasseswithmembers [,modifier,...] class_specification
    Specifies classes and class members to be preserved, on the condition that all of the
    specified class members are present. For example, you may want to keep all
    applications that have a main method, without having to list them explicitly.
    

    I think that means that entire R does not get keeped, but only the fields we use or specify with this rule.

  13. AllanWang commented on Jul 8, 2017

    @AllanWang
    AllanWang
    on Jul 8, 2017
    ContributorAuthor
    More actions

    @rubengees I think it means that it does, since the only constraint is that a class contains a define_ string and it's preserving the entire class rather than just some members. I'm still waiting for travis to build so I can decompile it later. Plus I think the reason it works with define_ is because the rest of the class is kept, otherwise all your library_ strings will be gone too.

    (Not a proguard expert either, so what you're saying is ideally what I want to happen)

  14. mikepenz commented on Jul 8, 2017

    @mikepenz
    mikepenz
    on Jul 8, 2017
    Owner
    More actions

    The only thing which can be maybe done in the future is to split up the core, and move all libraries to a different module. So you can either use the module with all the resources, or you manually add the resources you want

  15. rubengees commented on Jul 8, 2017

    @rubengees
    rubengees
    on Jul 8, 2017
    Contributor
    More actions

    I just decompiled my app and the R file is really small. I think it works the way we want to (I could be mistaken of course).

  16. mikepenz commented on Jul 8, 2017

    @mikepenz
    mikepenz
    on Jul 8, 2017
    Owner
    More actions

    @rubengees just drag&drop the apk onto Android Studio 3.0, it has a really cool visualisation, and also shows the contained resources

  17. AllanWang commented on Jul 8, 2017

    @AllanWang
    AllanWang
    on Jul 8, 2017
    ContributorAuthor
    More actions

    @mikepenz The issue still stands with all the external libraries with their strings,

    Using the rules defined above definitely cleans it a fair bit though, since it seems to remove all the appcompat resources.

    My R class with from 6k variables to 3k, and About library went from 3709 to ~300.

    For the app, the size

    • with the proguard above is 3.92
    • without proguard is 3.98
    • with proguard and no R restrictions is 3.91
  18. mikepenz commented on Jul 8, 2017

    @mikepenz
    mikepenz
    on Jul 8, 2017
    Owner
    More actions

    well I can't do anything about external libraries.

    The only reason the R class has to be kept is for the auto-detection. You can enable proguard, don't add the rule, and just manually set which libraries needs to show up

  19. AllanWang commented on Jul 8, 2017

    @AllanWang
    AllanWang
    on Jul 8, 2017
    ContributorAuthor
    More actions

    Our cases are for proguard + shrink + no auto detection. Because without this rule those strings will be gone anyways. I don't think any changes need to be done on your end since it's fine the way it is, but perhaps the proguard lines can be added to the readme for those who want to shrink their resources as much as possible and are willing to input libraries manually.

    Thanks rubengees!

    -keepclasseswithmembers class **.R$* {
        public static final int define_*;
    }
    
    Reacted by Roman Kuleshov and Mateusz Kwieciński
  20. rubengees commented on Jul 8, 2017

    @rubengees
    rubengees
    on Jul 8, 2017
    Contributor
    More actions

    @AllanWang My pleasure :)
    @mikepenz I could send a PR if you like.

  21. mikepenz commented on Jul 8, 2017

    @mikepenz
    mikepenz
    on Jul 8, 2017
    Owner
    More actions

    @rubengees already writing the README update :)

  22. mikepenz commented on Jul 8, 2017

    @mikepenz
    mikepenz
    on Jul 8, 2017
    Owner
    More actions

    https://github.com/mikepenz/AboutLibraries/blob/develop/README.md#proguard

    Thank you @rubengees & @AllanWang

    Reacted by Allan Wang and Tiago Araujo
    Reacted by Ruben Gees
  23. mikepenz
    closed this as completedon Jul 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @mikepenz
    mikepenz

Labels

question

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402792 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.