Android Application Packages or APKs are getting obese. As a developer, you need to keep the API size to bare minimum as this ensures your app’s popularity. This is easier said than done – and the easiest step would be to hire a professional Android app development company (given the obvious cost benefits and the general experience of the developers). But, if you are a developer, or intending to hire a developer, here comes a list of few tips from one of the leading firms offering Android application development services.
It’s no secret to anyone; APKs out there are getting bigger and bigger. While simple/single-task apps were 2MB at the time of the first versions of Android, it is now very common to download 10 to 20MB apps. The explosion of APK file size is a direct consequence of both users expectations and developers experience acquisition. Several reasons explain this dramatic file size increase:
- The multiplication of dpi categories ([l|m|tv|h|x|xx|xxx]dpi)
- The evolution of the Android platform, development tools and the libraries ecosystem
- The ever-increasing users’ expectations regarding high quality UIs etc.
Publishing light-weight applications on the Play Store is a good practice every developer should focus on when designing an application. Why? First, because it is synonymous with a simple, maintainable and future-proof code base. Secondly, because developers would generally prefer staying below the Play Store current 50MB APK limit rather than dealing with download extensions files. Finally because we live in a world of constraints: limited bandwidth, limited disk space, etc. The smaller the APK, the faster the download, the faster the installation, the lesser the frustration and, most importantly, the better the ratings.
Reducing APK file size
Reducing the file size of an APK can be done with several techniques. Because each app is different, there is no absolute rule to put an APK on diet. Nevertheless, an APK consists of 3 significant components we can easily act on:
- Java source code
- Native code
The tips and tricks below all consist on minimizing the amount of space used per component reducing the overall APK size in the process.
Reduce the flab by getting rid of all unused dependency libraries. Clean it regularly as this will help achieve small APKs. For older projects this can get tougher but you need to keep APKs that are essential to the app. . Clean it continuously. Focusing on keeping a clean and up-to-date code base is generally a great way to produce small APKs that only contain what is strictly essential to the app.
Maintaining an unpolluted code base is generally easier when starting a project from scratch. The older the project is, the harder it is. As a fact, projects with a large historical background usually have to deal with dead and/or almost useless code snippets. Fortunately some development tools are here to help you do the laundry.
This is one tool that would simplify your task. It optimizes and shrinks the code during compilation. Its ‘tree shaking’ feature goes all the paths and detects unused snippets and strips them to create a leaner APK. It also renames fields and classes to make the code lightweight.
Be opinionated about resources
Android supports a very large set of devices at its core. In fact, Android has been designed to support devices regardless of their configuration: screen density, screen shape, screen size, etc. As of Android 4.4, the framework natively supports various densities: ldpi, mdpi, tvdpi, hdpi, xhdpi, xxhdpi and xxxhdpi. Android supporting all these densities doesn’t mean you have to export your assets in each one of them.
Don’t be afraid of not bundling some densities into your application if you know they will be used by a small amount of people. I personally only support hdpi, xhdpi and xxhdpi2 in my apps. This is not an issue for devices with other densities because Android automatically computes missing resources by scaling an existing resource.
Reduce Resources Configurations
You might be using external libraries such as Facebook SDKAndroid Support Library or Google Play Services. These also bring in a lot of resources that aren’t useful to the app and increase the file size. Doing away would help reduce APK size.
Reuse whenever possible
Reusing stuff is probably one of the first important optimization you learn when starting developing on mobile. In a ListView or a RecyclerView, reusing helps you keep a smooth scrolling performance. But reusing can also help you reduce the final size of your APK. For instance, Android provides several utilities to re-color an asset either using the new android:tint and android:tintMode on Android L or the good old ColorFilter on all versions.
Apt comes with a loss less image compression algorithm. For instance, a true-color PNG that does not require more than 256 colors may be converted to an 8-bit PNG with a color palette. While it may reduce the size of your resources, it shouldn’t prevent you from embracing the lossy PNG preprocessor optimization path. A quick Google search yields several tools such as piquant, Image Alpha or Image Optimization. Just pick the one that best fits your designer workflow and requirements and use it!
Designing is all about getting the best out of a set of constraints. The weight of an APK file is clearly one of these constraints. Don’t be afraid of pulling the strings out of one aspect of your application to make some other better in some ways. For instance, do not hesitate to reduce the quality of the UI rendering if it reduce the size of the APK and make the app smoother. 99% of your users won’t even notice the quality drop while they will notice the app is light-weight and smooth. After all, your application is judged as a whole, not as a sum of severed aspects. For comprehensive suggestion and hand holding towards developing your next android app, get in touch with us today!