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?
- <style name= "apptheme" parent="Android:Theme.Light">
- </style>
Third, change the class file inherits the object is activity
[Java]View PlainCopyprint?
- 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