降低Android应用程序(APK)尺寸 [英] Reducing android app (apk) size

查看:343
本文介绍了降低Android应用程序(APK)尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会是现在公布我在谷歌Play商店的第一个应用。我在我的应用程序中使用已融为一体pressed图像。而且我有一个关于应用程序的大小一些问题。

I would be now publishing my first app on Google play store. I have already compressed images used in my app. And I have some questions regarding the app size.

如果应用程序的大小是小于2 MB,则有较少的用户会卸载应用程序的机会,是我的这种说法真的属于教育领域?

If the size of app is less that 2 MB then there are less chances that user will uninstall the app, is my this statement true for apps belonging to education field ?

不过,当我看到我的apk文件在Windows上,它显示3.10 MB,但是当它被安装在设备从应用程序的信息看它表明:

However, When I see my apk file in windows it shows 3.10 MB but when it gets installed in device as viewed from App info it shows:

Total............................8.68 MB
App..............................7.02 MB
USB storage app..................0.00 B
Data.............................1.66 MB (perhaps it is the size of sqlite db + ttf's)
SD card..........................0.00B

那么,为什么我看到在我的应用程序的大小那么多的增加,能不能最小化?

So, Why do I see that much increase in my app size, Can it be minimized ?

和,我使用4库(罐),在我的项目,该项目是在 Android的私人图书馆,但这些图书馆有自己的这个文件夹外还副本。

And, I am using 4 libraries (jars) in my project which are in Android Private Libraries, but these library have their copy outside this folder also.

是否可以更安全地删除它们,和放大器;删除它们可以帮助减少APK大小?

Is it safer to delete them, & deleting them can help to decrease apk size?

此外,我也参观了很多的网页描述什么 Proguard的不,我才真正明白Proguard的是如何降低的apk的大小,它缩小,优化和混淆我们的code通过删除未使用code和重命名类,字段和方法与语义模糊的名字。结果是较小尺寸的apk文件,它是更难以逆向工程。但我不知道应该怎么做我的 ProGuard的-project.txt 应该是什么样子?
我在我的应用程序中使用4库即<$c$c>easyfacebookandroidsdk_2.3.jar,<$c$c>android-support-v7-appcompat.jar,<$c$c>google-play-services.jar &放大器; Android的支持 - v4.jar

Also I have visited many web pages describing what Proguard does, I truly understand how Proguard reduces size of apk, it shrinks, optimizes, and obfuscates our code by removing unused code and renaming classes, fields, and methods with semantically obscure names. The result is a smaller sized .apk file that is more difficult to reverse engineer. But I do not know How should be my proguard-project.txt should look like ?
I am using 4 libraries in my app namely easyfacebookandroidsdk_2.3.jar,android-support-v7-appcompat.jar,google-play-services.jar & android-support-v4.jar.

目前我的 ProGuard的-的properties.txt 看起来是这样的:放大器;此外,它不使用的WebView

Currently my proguard-properties.txt looks like this & also it do not uses WebView

# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;  
#}
-keep class com.facebook.** { *; }
-keepattributes Signature

所以,我应该补充什么线我的 ProGuard的-的properties.txt ,以便它可以删除未使用的引用,类等,在为了减少APK大小?

So, what lines should I add in my proguard-properties.txt so that it can remove unused references,classes,etc., in order to reduce the apk size ?

使用AndroidUnusedResources.jar可在<一href="https://$c$c.google.com/p/android-unused-resources/">https://$c$c.google.com/p/android-unused-resources/发现在Android项目未使用的资源。

Using AndroidUnusedResources.jar available at https://code.google.com/p/android-unused-resources/ finds unused resources in android project.

我觉得这是同样的事情,它的ProGuard已经做了什么?或者应该也使的ProGuard后才能使用?

I think this is the same thing which proguard has already done ? Or should it also be used after enabling proguard ?

你也可以提到在你的答案任何丢失,你觉得应该共享。
在此先感谢...

Also you can mention in your answer anything that is missing which you feel should be shared.
Thanks in Advance...

推荐答案

几乎完全是因为你的资源文件夹的图像!你应该在绘制-MDPI,-hdpi,xhdpi文件夹约4份每幅图像。唯一的区别是,theu都是不同的大小。

So, Why do I see that much increase in my app size, Can it be minimized?

Almost solely because of your res folder images! You should have around 4 copies of each image in the drawable-mdpi, -hdpi, xhdpi folders. The only difference is that theu are all different sizes.

机会是不会有这些jar文件的多个副本!只是一份副本,它的链接!

Chances are there aren't multiple copies of those jar files! Just one copy with links to it!

是的,你说的是对的Proguard的。但是,认识到你所谈论的文本文件在这里。他们是非常小的。我的意思是非常小的尺寸(千字节明智)。你的问题是什么,在兆字节(MB)的大小。这是图像!!!!

Yes, what you said was right about Proguard. However, realize that you are talking about text files here. They are really small. I mean really small in size (kilobyte-wise). Your problem is something in the megabyte (MB) size. That is images!!!!

重复。这是图像!!!!

启用ProGuard的将节省一点点的大小明智的。

Enabling proguard will save a little bit size-wise.

是的,这些都是比较重要的,你的情况。请阅读并应用这些。祝你好运!

Yes, these are all more important in your case. Please read and apply these. Good luck!

如果用户发现你的应用程序有帮助,那么他们将无法将其卸载;然而,有几件事情你可以做

If a user finds your app helpful, then they won't uninstall it; however, there are several things you can do

  • 你能移动图像到Web 异步到您的应用程序?
  • 确保您的文件的完全融为一体pressed 尽可能多地。使用 pngquant tinypng
  • 检查任何重复的图片。你也许可以使用 9补丁吧。
  • 您也许能为让你自己可绘制作为特定的图像。
  • 允许用户为将数据转移到SD卡

  • Can you move images to the web and async them into your app?
  • Make sure your files are completely compressed as much as possible. Use pngquant or tinypng.
  • Check for any repetition in the images. You might be able to use 9-patch for it.
  • You might be able to make your own drawables for certain images.
  • Allow users to move data to an SD card.

后的应用程序已 Play商店一会儿检查开发者控制台,看看它的屏幕尺寸/密度使用最少的。 从你的应用程序中删除该文件夹绘制!这可以减小尺寸量好!但是,检查我的编辑下面这个方法!

After the app has been in the Play Store for a while, check the Developer Console and see which screen size/density is used the least. Remove that drawable folder from your app! This could reduce the size a good amount! But, check my edit below for the cons of this approach!!

您可能想显示一些图像,因为这将让我们看到你正在处理的是什么

You might want to show a few of the images, as that would allow us to see what you are dealing with

@AshwinñBhanushali具有强大的答案这里的问题,我没有回答的一部分,但他基本告诉你,没有什么可以真正做到除了我说的话,加上一个想法或2级以上。

@Ashwin N Bhanushali Has a great answer here for the part of the question I did not answer, but he basically told you that there was nothing you could really do except what I said, plus an idea or 2 more.

我也有另外一个想法是基于对他的想法,甚至会更好一说,由于Android Studio不包括该项目的绘制,LDPI文件夹了。所以,如果你使用Eclipse只会有帮助,我的扩展

I did have another idea that was based on one of his ideas that would be even better, because Android Studio does not include the drawable-ldpi folder in the project anymore. So it would only be helpful if you use Eclipse, mine expands

  1. 松开APK到谷歌作出建议修正后的Play商店
  2. 经过一段时间已经过去了 - 一个星期,一个月,等等 - 你可以的检查统计应用程序的中的 = https://developer.android.com/distribute/googleplay/developer-console.html#app-stats">Google Play开发者控制台
  3. 查找屏幕尺寸桶绘制-MDPI,-hdpi,-xhdpi,-xxhdpi 的),它们的用最少的!你可以完全删除这些桶从你的应用程序!
  1. Release the APK into the Google Play Store after making the recommended fixes
  2. After some time has passed -- a week, a month, etc -- you can check the stats of your application in the Google Play Developer Console.
  3. Look for the screen size buckets(drawable-mdpi, -hdpi, -xhdpi, -xxhdpi) that are used the least! You could remove those buckets from your app altogether!

这工作,因为图片占用比的办法多个字节的文本文件。而所有这些可绘有同样在他们的图片只是大小不同的)。 删除从少铲斗的图像可以节省大量的空间!!

This works because pictures take up way more bytes than text files. And all those drawables have the same images in them (just different sizes). Removing the images from less used buckets can save a lot of space!!

请留意您的应用程序消除这些桶将意味着的您的应用程序将不得不这样做对那些使用删除桶的手机更多的工作。 的应用程序可能会减慢对这些用户的;然而,应用程序的大小可减小的更多。

Take note that removing those buckets from your app will mean that your app will have to do more work on those phones that use the removed buckets. The app might be slower for those users; however, the app size can be reduced more.

文本文件占用几乎没有。您可以在文件系统中的外观为您的项目!

Text files take up almost nothing. Take a look in the file system for your project!

在下面的图片。检查...大小

In the picture below. Check the size of...

  • 的Java 文件夹
  • RES 文件夹
  • the java folder
  • the res folder

在你的情况,你会看到java文件夹是可能是非常小的尺寸 10到几百KB的的);但是,您将看到RES文件夹是的规模确实大若干MB的!的)。

In your case, you will see that the java folder is probably really small in size (10 through a few hundred KBs); however, you will see that the res folder is really large in size (several MBs!).

这意味着任何COM pression,或减少您的 code基很小,不值得!

因此最好减少APK大小的方法是按照上面我的指示!

下面是一个测试,你可以马上做到,看到的绝对最大值(加上更多),像工具 Proguard的 AndroidUnusedResources.jar 将减少的大小APK文件!

Here is a test that you can do right away and see the absolute maximum (plus more) that tools like Proguard, and AndroidUnusedResources.jar will reduce the size of the APK file!

您所要做的就是删除所有 $ C $从项目C除了类声明。执行相同的抽象类,接口,枚举,等等......你的项目结构应保持不变,你不应该使用任何外部库在所有然后。

What you have to do is remove ALL code from your project except for the class declarations. Do the same for Abstract classes, Interfaces, Enums, etc... Your project structure should stay the same, and you should not be using any external libraries at all then.

  1. 所以,你将有这样的事情对于所有类...

  1. So you will have something like this for all of your classes...

public class CustomClass {

    private String variable; // List of variables

    public CustomClass() { ... } // List of constructors

    public getVariable() { ... } // List of Assessors

    public setVariable(String val) { ... } // List of Mutators

    private String helperMethods() { ... } // List of helper and other methods

}

  • 您应该删除所有code类,接口,枚举,等里面如下所示;然而,离开所有的图像孤独! ......

  • You should remove all the code inside of the classes, interfaces, enums, etc to look like the following; however, leave all your images alone!! ...

    public CustomClass {
    
        // Everything is removed!! No libraries used, nothing. Unless certain classes 
        //     require some methods like Activity. Those methods should be empty though!
    
    }
    

  • 现在编译并生成项目。

  • Now compile and build your project.

    检查新的APK大小,以你目前的APK。

    Check the new APK size to your current APK.

    • 这将是最小的COM pressed大小的文件,你可以用你的code ++实现。是的,你的程序不会做任何事情,但这是除了点。你在乎的大小在这里,这仅仅是一个考验。

    安装在手机上的应用程序,并检查新的应用程序的大小,以你目前的应用程序的大小

    Install the app on your phone, and check the new app size to your current app size

    • 这将是可能的最小uncom pressed大小的文件你可以用你的code ++实现。是的,你的程序不会做任何事情,这只是一个测试。

    是没有意义的,在这个阶段。这是一个测试,看看在那里你会花你的个人资源,应用程序尺寸的减小。

    If you notice that the 2 apps are still around the same size, then spending all your time with Proguard and AndroidUnusedResources.jar is meaningless at this stage. This is a test to see where you would spend your personal resources in app size reduction.

    这篇关于降低Android应用程序(APK)尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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