简体   繁体   中英

The size of an application, how is it determined

I was trying something out, that is a custom log-in activity with just a TextView, a Button and two EditTexts, and no variables created anywhere. No images, nothing but everything's code (xml layout and default onCreate() code). And my application size ended up with 3.2MB. My favourite calculator "RealCalc" (which does almost every mathematical calculations other than just simple arithmetic) is ~765KB.

So my question is, is there way to achieve such small sizes?

I think because of Android Support Library, they are included automatically even you create a simple project. The simple way to check is changing the apk file name to .zip then extract it, you can see the content

Proguard can achieve such small sizes.

The ProGuard tool shrinks, optimizes, and obfuscates your 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.

To quickly test/play with it:

Set minifyEnabled to true in your app's build.gradle file.

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

Then, create a release build:

./gradlew assembleRelease

From my personal experience, proguard can shrink the apk size by 50% for a complex application.

However, proguard rules may be hard to configure. I also found this repo krschultz/android-proguard-snippets that has proguard snippets for popular android dependencies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM