Specifying ndkVersion in build.gradle outputs apk with smaller download size?

Viewed 105

So in my app with native libs (some precompiled .so files, some being compiled during build), if I don't specify ndkVersion in build.gradle, then it generates apk ~8.8 MBs in size (download size as determined by apkanalyzer). When ndkVersion is set to 17.2.4988734, it generates apk sized at ~7.6 MBs. When ndkVersion is set to 22.1.7171670, it generates apk sized at ~7.2 MBs.

I get that there maybe optimizations in NDK 22.1.7171670 when compared to 17.2.4988734. What I don't get is why there's sizable (pun intended) difference in native libs when not specifying ndkVersion?

Also, the size change is mostly in the precompiled .so files and not in the ones generated by the build system when generating the apk.

1 Answers

From documentation:

When you install the NDK, Android Studio selects the latest available NDK. For most projects, installing this default version of the NDK is sufficient. If your project needs one or more specific versions of the NDK, though, you can download and configure specific versions.

So, NDK 22.1.7171670 is better than the latest NDK version you have (Optimized for size wise). and this is reasonable because most new releases optimize new code for speed first then worries about size in later versions.

Related