如何优化(减少)我的Android应用程序的大小 [英] How to optimize(reduce) the size of my android app

查看:78
本文介绍了如何优化(减少)我的Android应用程序的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个仅包含2个Web视图的android应用,其中包含一些Java脚本,内置的PDF阅读器API约2 MB,所有PDF(压缩)约25 MB,其他图像(也已压缩)等少于1 MB,大约等于30 MB.因此,在生成应用后,我的应用大小约为55 MB.我认为这是不可接受的. 所以,为什么我的应用程序有这么大的尺寸,我又怎么能减小Android应用程序的尺寸呢?

I created an android app that contains just 2 webviews with some java script in them,an inbuilt PDF reader API which weighs around 2 MB and all the PDF's(Compressed) which are around 25 MB and other images(Also compressed) etc less than 1 MB which tallies to around 30 MB.So after generating the app my app size is around 55 MB.Which i believe is not acceptable. So,why is my app having so much large size and also how can i even more reduce the size of my android app.

推荐答案

发现"lib"为15 MB,大约是我应用程序大小的35%,这是不可接受的,因为我只使用了2 MB的单个ext库.

found out that the "lib" is 15 MB which is around 35% of my app size which is not acceptable as i had used only a single ext library of 2 MB

您错误地估计了该库的大小及其依赖项.假设您自己没有使用NDK,则该库正在使用NDK,或者其依赖项正在使用该库.该库的大小大致与此PDF查看器的大小匹配,尽管我不知道这是否是特定的您正在使用的.

You miscounted the size of that library and its dependencies. Assuming that you are not using the NDK yourself, then either that library is using the NDK, or its dependencies are using that library. That library size roughly matches that of this PDF viewer, though I do not know if that is the specific one that you are using.

该PDF查看库的文档为什么库会使您的APK大:

The documentation for that PDF viewing library has a section on why the library makes your APK big:

Android PdfViewer依赖于PdfiumAndroid,后者是许多体系结构的一组本机库(将近16 MB). Apk必须包含所有这些库,才能在市场上可用的每种设备上运行.幸运的是,Google Play允许我们上传多个apk,例如每个架构一个. 这里.最重要的部分是使用APK Splits改进多个APK的创建和版本代码处理,但全文值得一读.您只需要在应用程序中执行此操作,而无需派生PdfiumAndroid左右.

Android PdfViewer depends on PdfiumAndroid, which is set of native libraries (almost 16 MB) for many architectures. Apk must contain all this libraries to run on every device available on market. Fortunately, Google Play allows us to upload multiple apks, e.g. one per every architecture. There is good article on automatically splitting your application into multiple apks, available here. Most important section is Improving multiple APKs creation and versionCode handling with APK Splits, but whole article is worth reading. You only need to do this in your application, no need for forking PdfiumAndroid or so.

您的选择是:

  • 按照文档中的建议进行操作,并使用ABI拆分使每个CPU架构具有单独的APK(仅当您通过某种支持每种架构的单独APK的分发方式(例如Play商店)时才有用)

  • Follow the advice in the documentation and use ABI splits to have separate APKs per CPU architecture (which only helps if you are distributing by some means that supports separate APKs per architecture, such as the Play Store)

使用其他PDF渲染选项

依靠ACTION_VIEW和用户选择的PDF查看器,从您的应用中删除PDF呈现功能

Eliminate the PDF rendering feature from your app, relying on ACTION_VIEW and the user's chosen PDF viewer

从应用中删除PDF,将它们转换为HTML/CSS/图像,并在WebView

Eliminate the PDFs from your app, converting them to HTML/CSS/images and rendering them in a WebView

这篇关于如何优化(减少)我的Android应用程序的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆