简体   繁体   中英

Including large Android Library Project inside an Android app (resulting APK size)?

I am planning on creating one huge Android library project that will serve as a framework for all our future apps (since a lot of the code will be shared between apps, I don't want to re-include and maintain it in separate apps).

For this I am planning to create one Android project that will serve as a basis or "container" for all main functionality that will be mostly available to the apps. However, some apps will have part of the functionality, while others will have different part of the functionality.

The whole library project will not be fully used by each individual app - only portions of it, related to that specific app.

My question is:

  1. How is this performance-wise and also:
  2. Does including a 2MB library app to a 500kb new Android app increase the resulting app-s APK size to ~2.5MB, considering that the small app will only use a small portion of the whole library? Or does it strip away classes from the library that are not needed from the production APK?
  3. If the size indeed increases to accomodate the whole library's size - how do we overcome this pitfall of the need to reinvent the wheel for each app and maintain shared code across apps.

I'm not sure how Android's/Eclipse apk exporters work.

How is this performance-wise

In terms of stuff like CPU speed, heap consumption, and the like, there should be no effect.

Does including a 2MB library app to a 500kb new Android app increase the resulting app-s APK size to ~2.5MB, considering that the small app will only use a small portion of the whole library? Or does it strip away classes from the library that are not needed from the production APK?

That will depend upon ProGuard. As Jakar notes, ProGuard removes unused classes. It's algorithms for determining "unused" are imperfect, and so sometimes it will retain classes that actually are not needed.

how do we overcome this pitfall of the need to reinvent the wheel for each app and maintain shared code across apps.

I'd start by having more than one library, and only linking an app to the libraries that it needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM