如何减小 Android APK 大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22269850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to reduce Android APK size?
提问by Arunima
I have developed a simple Android application. Its APK size is 8MB. Can anyone tell me how to reduce the APK size?
我开发了一个简单的 Android 应用程序。它的 APK 大小为 8MB。谁能告诉我如何减小 APK 大小?
回答by orip
- Try enabling ProGuard, even without obfuscation. It will remove unused Java code from your dependencies.
- See if you have unneeded dependencies - JARs that you've added but aren't using
- Check your resources for large images or other files. You may want to change their format or resolution, or remove them if they're not in use.
- Optimize your final APK (after ProGuard) with Facebook's ReDex. This should reduce the code size as well as potentially improve performance.
- 尝试启用ProGuard,即使没有混淆。它将从您的依赖项中删除未使用的 Java 代码。
- 查看您是否有不需要的依赖项 - 您已添加但未使用的 JAR
- 检查您的资源中是否有大图像或其他文件。您可能想要更改它们的格式或分辨率,或者在它们不使用时将其删除。
- 使用Facebook 的 ReDex优化您的最终 APK(在 ProGuard 之后)。这应该会减少代码大小并潜在地提高性能。
回答by Piyush
1) First you need to enable Proguardeven without obfuscation. It will remove unused Java code from your dependencies.
1) 首先,即使没有混淆,您也需要启用Proguard。它将从您的依赖项中删除未使用的 Java 代码。
2) Second, use 9-patch imagesinstead of very high resolution images.
2) 其次,使用9-patch 图像而不是非常高分辨率的图像。
3) Remove some unnecessary code and also JAR files that haven't be used.
3) 删除一些不必要的代码以及没有使用的JAR 文件。
4) Ensure you are using .png images instead of .jpg.
4) 确保您使用的是 .png 图像而不是 .jpg。
5) Use different images for different screen resolutions.
5)为不同的屏幕分辨率使用不同的图像。
6) Check your layout folder for unnecessary XML files
6) 检查您的布局文件夹中是否有不必要的 XML 文件