是否有任何黑客方式?例如部分resource.arsc文件然后在应用程序创建时从资产(我压缩它)加载整个arsc,或者将其他语言文件夹(zh_CN,jp)移动到资产中以便我可以压缩它。
答案 0 :(得分:3)
Cyril Mottier有一篇关于此的非常好的博文: Putting Your APKs on Diet
他的帖子标题:
具有良好的编码卫生
...Get rid of all unused dependency libraries...projects with a large historical background usually have to deal with dead and/or almost useless code snippets.
运行Proguard
Proguard is an extremely powerful tool that obfuscates, optimizes and shrinks your code at compile time
广泛使用Lint
Proguard works on the Java side. Unfortunately, it doesn’t work on the resources side...[lint] generates an HTML-report and gives you the exhaustive list of resources that look unused under the “UnusedResources: Unused resources” section. It is safe to remove these resources
关于资源的看法
Android has been designed to support devices regardless of their configuration: screen density, screen shape, screen size, etc. As of Android 4.4, the framework natively supports various densities: ldpi, mdpi, tvdpi, hdpi, xhdpi, xxhdpi and xxxhdpi. Android supporting all these densities doesn’t mean you have to export your assets in each one of them.
最小化资源配置
Android development often relies on the use of external libraries such as Android Support Library, Google Play Services, Facebook SDK, etc. All of theses libraries comes with resources that are not necessary useful to your application. For instance, Google Play Services comes with translations for languages your own application don’t even support.
压缩图像
A quick Google search yields several tools such as pngquant, ImageAlpha or ImageOptim. Just pick the one that best fits your designer workflow and requirements and use it!
我想添加一个非常有用的在线服务:TinyPNG
限制架构数量
Android is generally about Java but there are some rare cases where applications need to rely on some native code...Sticking to armabi and x86 architecture is usually enough in the current Android eco-system.
尽可能重用
For instance, Android provides several utilities to re-color an asset either using the new android:tint and android:tintMode on Android L or the good old ColorFilter on all versions.
或
You can also prevent packaging resources that are only a rotated equivalent of another resource.
在适当的时候渲染代码
In some cases rendering graphics directly for the Java code can have a great benefit. One of the best example of a mammoth weight gain is with frame-by-frame animations.
答案 1 :(得分:1)
删除不必要的资源(图片等)。这是最有效的方法。然后删除不必要的类和库。
答案 2 :(得分:1)
有很多方法,但最后都是一样的,因为它与不必要的事物有关。
您只需要删除不必要的资源,类,库。
我可以说我们有5个文件夹可以将一个图像放在所有不同大小的文件夹中,所以我建议您更喜欢 9补丁图像而不是5个不同的图像(无论何时可以放置)。使用这种方式,您可以最有效地减小apk大小。
答案 3 :(得分:1)
尝试启用ProGuard,即使没有混淆。它将从依赖项中删除未使用的Java代码。 看看你是否有不必要的依赖关系 - 你已经添加但未使用的JAR 检查资源是否有大图像或其他文件。您可能想要更改其格式或分辨率,或者如果它们未被使用则将其删除。 您尽可能压缩.jpg文件,这将大大减少.apk文件的大小。像Paint.NET这样免费的工具可以帮助你做到这一点。它有很好的调整大小选项。