How Android studio reduces APK volume

Source: Internet
Author: User

Recently, a small calculator has been developed with Androidstudio, and the code adds up to less than 200 lines. However, a problem has been encountered, the size of the exported apk file reached 1034K. It's not scientific, so just do it yourself and simplify the APK. Now let's learn how to reduce the size of an apk to the example of Hello World.

New project, minimum version support 2.3.3, other default. The project catalog is this:

We direct signature export APK, see how size, 1M Ah! (⊙o⊙) What the hell:

How could it be, huh? Haven't written the code yet, it's already 1 m. Check the code, we will find that the project has automatically added a V7 backwards-compatible package, in order to enable the lower version (4.0 or less) Android can use the high version (4.0 and above) features.

First, if we do not use this compatibility package can be deleted, file-->projectstructure-->app-->dependencies (shortcut key: Ctrl+shift+alt+s), That is, a package named like this com.android.support:appcompat-v7:22.2.0

Second, after the deletion, the project began to error. In this case, you want to delete the Showasaction property and change the Styles.xml resource file inside the menu resource file:

Delete the code marked with the Red line:

To change the Style.xml resource file:

[HTML]View PlainCopyprint?
    1. <style name= "apptheme" parent="Android:Theme.Light">
    2. </style>

Third, change the class file inherits the object is activity

[Java]View PlainCopyprint?
    1. Public class Mainactivity extends Activity

Importing activity packs and removing unnecessary packages

Four, then as long as clean the project, you will find that there is no mistake.

Five, we directly export apk to see how the size of the present, it is really poor days so big:

Six, can choose to open proguard:http://developer.android.com/tools/help/proguard.html

Reference:

http://blog.csdn.net/tim_yip/article/details/47022875

Http://www.2cto.com/kf/201608/540670.html

Http://www.cnblogs.com/soaringEveryday/p/5254520.html

How Android Studio reduces APK volume

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.