Android Question Get sizes of libraries to optimize resulting APK's?

JohnC

Expert
Licensed User
Longtime User
To keep things efficient, I share a code module among my projects that contains a bunch of often-used sub routines.

However, some of these routines require the JavaObject lib, and others require the Phone lib, etc.

My understanding is that if I have a subroutine that uses a library, even if my app doesn't actually call that routine, the compiler will still include that routine and it's associated lib into the APK, making it bigger then it needs to be. Is this a correct understanding?

Going on the assumption that I do understand this correctly, I want to keep the APK size down. So I started using conditional symbols like USESJO (uses javaobject) and USESPHONE, etc so it won't include routines that need certain external libraries if I don't need them. For example, if I don't need any routines that use the JO, I won't use the USEJO symbol so the compiler wont include those routines or the JO lib itself in the APK.

But this is starting to get complex because some routine need both JO and PHONE, etc. Yeah, I could break things up into separate code modules, but that will get messy too.

So, before I spend anymore time trying to optimize this further, is there a way to find out how much bigger the APK will get if I include a particular lib, like the JavaObject lib?

This way, if I can find libs that are very small and won't effect the APK size significantly, I wont worry about trying to optimize them and just keep the routines that use these small libs enabled all the time and not waste time with extra conditional symbols.

Also, I understand that simply knowing the lib size might only be half the story because certain libs could require the compiler to include other libs, such as an android support lib, which could be much bigger then the original lib. So, in this case, is there a way to trace what libs invoke the biggest changes to an APK's size?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
My understanding is that if I have a subroutine that uses a library, even if my app doesn't actually call that routine, the compiler will still include that routine and it's associated lib into the APK, making it bigger then it needs to be. Is this a correct understanding?
Not really. JavaObject and Phone libraries are small enough that you can just ignore them. They will add less than 100k to the app. JavaObject is less than 10kb and the phone library is about 80kb.

Sooner or later you will need to add a library that depends on Google Play Services. The play services will add a few MBs to your app.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Thanks Erel,

But is there a way I can figure out the size effects for other libs like reflection, appcompat, and many others that I use, or are most of them very small and the only one that I really need to be concerned about is anything that uses google services?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Almost all apps depends on components from Google Play Services so you can assume that GPS will be referenced and forget about it as well.

Bottom line is that your app size will be around 3 - 4 mb (before resources) and you don't need to worry about the libraries sizes. Add whichever library that you need.
 
Upvote 0
Top