I wanted to see how small an Android APK can be. I was able to squeeze it as small as 1,600 bytes: it has a NativeActivity in C that fills the screen with a gradient and responds to input. The source is one C file, a tiny manifest and a Makefile. I wrote a small Python script that trims the library and the manifest, and signs the APK.
- apksigner pads the v2 signing block to 4 KB, for a hash tree Android does not need to install the app. It turned a 1,299 byte unsigned APK into 8,349.
- Android's ELF loader requires section headers, but reads only two of them, and only some of their fields.
- aapt2 hardcodes UTF-16 for the manifest's strings, though Android reads UTF-8. Android looks attributes up by resource id, so their names can be empty strings.
- The v2 verifier checks that the certificate holds the signing key, but never checks the certificate's own signature. With an empty signature, empty names and a weak compressed P-224 key, Android still installs it.
I wanted to see how small an Android APK can be. I was able to squeeze it as small as 1,600 bytes: it has a NativeActivity in C that fills the screen with a gradient and responds to input. The source is one C file, a tiny manifest and a Makefile. I wrote a small Python script that trims the library and the manifest, and signs the APK.
My starting point was the same app written in the style of the NDK sample: 8,220 bytes. https://github.com/android/ndk-samples/tree/main/native-acti...
What surprised me the most:
- apksigner pads the v2 signing block to 4 KB, for a hash tree Android does not need to install the app. It turned a 1,299 byte unsigned APK into 8,349.
- Android's ELF loader requires section headers, but reads only two of them, and only some of their fields.
- aapt2 hardcodes UTF-16 for the manifest's strings, though Android reads UTF-8. Android looks attributes up by resource id, so their names can be empty strings.
- The v2 verifier checks that the certificate holds the signing key, but never checks the certificate's own signature. With an empty signature, empty names and a weak compressed P-224 key, Android still installs it.
You can find more details in these two articles:
https://regisvidal.com/articles/tiny-android-app-in-c/
https://regisvidal.com/articles/tiny-android-app-in-c-again/