Skip to content
Aditya Bhalsod
← Mobile
MobileIntermediate

Shipping a 25 KB Android App With Zero Dependencies

How I kept Net Speed Monitor's release APK to roughly 25 KB using plain Java, Android's TrafficStats API, a hand-drawn Canvas gauge and an aggressive R8 setup.

  • #android
  • #java
  • #performance
  • #r8
Contents
  1. Start from what the platform already gives you
  2. Keep the service alive, cheaply
  3. Survive reboots
  4. Don't wake the CPU for nothing
  5. Draw the UI yourself
  6. Let R8 finish the job
  7. When this approach makes sense

Most Android "hello world" projects weigh a few megabytes before you write a single line, because the default template pulls in AndroidX, Material Components and Kotlin's standard library. For Net Speed Monitor I wanted the opposite: an app that does one thing, shows live upload and download speed in the status bar, and costs users almost nothing to install.

The release APK ended up at roughly 25 KB. Here is what got it there.

Start from what the platform already gives you

The core of a speed meter is two numbers: how many bytes the device has received and sent so far. Android has exposed those since API level 8 through android.net.TrafficStats.

Java
long rx = TrafficStats.getTotalRxBytes();
long tx = TrafficStats.getTotalTxBytes();

Sample them once per second, subtract the previous sample, and you have bytes per second. No networking library, no permissions beyond what a foreground service needs.

Keep the service alive, cheaply

The numbers have to keep updating while the app is in the background, which on modern Android means a foreground service with a persistent notification. That notification doubles as the status-bar readout, so it isn't wasted.

Survive reboots

A BroadcastReceiver for BOOT_COMPLETED restarts the service after the phone reboots. It's a dozen lines and means users set the app up once and forget about it.

Don't wake the CPU for nothing

Updating once a second is plenty. I use a single Handler on the main looper rather than a scheduled executor, and stop posting updates when the screen is off. Nobody is looking at the status bar then.

Draw the UI yourself

The in-app screen shows a speed gauge. Instead of a charting library, it's a custom View that overrides onDraw and uses Canvas.drawArc for the dial and drawText for the labels. The whole thing is a few hundred lines of Java and adds nothing to the APK beyond the compiled bytecode.

ApproachRough size costNotes
Charting libraryhundreds of KBFlexible, mostly unused here
Material components1 MB+Great for full apps
Custom Canvas viewa few KBExactly what's needed, nothing more

Let R8 finish the job

With no third-party code, R8 has an easy time. The relevant Gradle settings:

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

The main rule is not to undo its work: avoid reflection, keep resources minimal, and ship vector drawables only where they replace multiple PNG densities.

When this approach makes sense

Zero dependencies is not a goal for every app. For a client product with complex screens, a design system and a team, AndroidX and Compose earn their weight. But for small, single-purpose utilities, starting from the platform and adding only what you can justify gives you an app that installs instantly, starts instantly, and is easy to keep working for years.

Found this useful? Share it with your team.

Keep reading

More from Mobile and beyond