简体   繁体   English

在Android应用程序中包含大型Android Library Project(导致APK大小)?

[英]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). 我正计划创建一个庞大的Android库项目,该项目将作为未来所有应用程序的框架(由于很多代码将在应用程序之间共享,因此我不想在单独的应用程序中重新包含和维护它) 。

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. 为此,我计划创建一个Android项目,该项目将作为所有主要功能的基础或“容器”,这些主要功能将大部分可用于应用程序。 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? 考虑到小型应用程序仅会使用整个库库的一小部分,是否将2MB库应用程序添加到500kb新的Android应用程序中是否会使生成的应用程序APK大小增加到〜2.5MB? Or does it strip away classes from the library that are not needed from the production APK? 还是从生产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. 我不确定Android / Eclipse APK导出程序的工作方式。

How is this performance-wise 这个表现如何

In terms of stuff like CPU speed, heap consumption, and the like, there should be no effect. 在诸如CPU速度,堆消耗之类的方面,应该没有任何影响。

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? 考虑到小型应用程序仅会使用整个库库的一小部分,是否将2MB库应用程序添加到500kb新的Android应用程序中是否会使生成的应用程序APK大小增加到〜2.5MB? Or does it strip away classes from the library that are not needed from the production APK? 还是从生产APK中删除了库中不需要的类?

That will depend upon ProGuard. 这将取决于ProGuard。 As Jakar notes, ProGuard removes unused classes. 如Jakar所述,ProGuard会删除未使用的类。 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. 我将从拥有多个库开始,然后仅将应用程序链接到所需的库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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