After including 6 libraries inside my library namespace, My library reached around 1.8 MB.
Your library is not 1.8 MB. It is possible that your library and its 8 dependencies combined (with transitive dependencies) is 1.8 MB. After all, one of those 8 dependencies is appcompat-v7
, and that's over 1 MB on its own, the last time I looked.
My library is already optimized.
No, it is not. You are depending on both Volley and OkHttp. These do the same thing. Get rid of one. Since you are also using Picasso, I recommend getting rid of Volley.
Is there a way to reduce my library size even after including all of 6?
Get rid of dependencies that you do not need (e.g., Volley).
If consumers of your library might not need all of the functionality of your library, split your library into pieces. For example, if some consumers of your library might want your networking code but not your UI code, you might create testtube-core
and testtube-ui
or something. testtube-core
would jettison things that are pure UI (e.g., appcompat-v7
), so for consumers that only need testtube-core
functionality, they get a smaller library. testtube-ui
would depend upon testtube-core
, so consumers using testtube-ui
would get all the dependencies, and your testtube-ui
code can call testtube-core
code to do what needs to be done.
Beyond that, you will have to rely on minification at the app level (e.g., ProGuard) to get rid of things that are unnecessary. Bear in mind that app developers might use your library and need things from your dependencies themselves. appcompat-v7
is a great example of this: just because you might need only a slice of appcompat-v7
does not mean that the app only needs that same slice.
This is why the comment advising you to clone the code and get rid of pieces is not very wise. At best, that might work for obscure libraries that app developers using your library might not need (e.g., whatever gun0912.ted:tedpermission
is). But creating your own hacked copy of appcompat-v7
or gson
or something will make the size issue worse, if the app also is using those libraries for other purposes.