0

I am trying to see if we can reasonably migrate from ndk-build to cmake for building our C++ library for android.

When I build exactly the same code with ndk-build to obtain a static library (.a), it generates a 542k file, whereas cmake will generate a 1.7Mb file.

I am using boost for a test build, only building the filesystem section.

Both are release builds.

I have searched to see if there are specific switches necessary to obtain roughly the same compilation, without success.

I am using the ndk version 19 for building, with the relevant toolchain file.

Is this a known problem ?

Simon
  • 2,208
  • 4
  • 32
  • 47
  • I'm guessing the .a file eventually gets linked into some .so file? Have you compared the sizes of the .so file that ends up in your APK? IIRC stripping happens later in the build process when you use CMake compared to ndk-build. – Michael Nov 02 '20 at 15:45
  • the .so is also 3 times the size of that built with ndk-build. – Simon Nov 02 '20 at 15:48
  • And you're comparing the files inside the APK, not some intermediate file? – Michael Nov 02 '20 at 15:49
  • I am comparing the size of libboostfilesystem.a in both builds, as well as the .so which it is linked to. – Simon Nov 02 '20 at 15:51

2 Answers2

0

CMake and ndk-build don't necessarily use the same flags. Static libraries are not stripped, so additional debug info that does not matter to the application can account for a lot of space.

If your eventual .so file that ends up in the APK (the one that has actually been stripped) is still large, use https://github.com/google/bloaty to diff the two and see which parts of the binary are larger.

Dan Albert
  • 10,079
  • 2
  • 36
  • 79
0

using cmake not strip debug symbols, my ndk version 21.3.6528147. using strip command to strip the debug symbols, e.g.

#for arm64-v8a
<ndk-path>/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-strip-s -v youlib.so

#for armeabi-v7a
<ndk-path>/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-strip -s -v youlib.so

see also How to enable stripping for cmake on Android

Jaeyo Keh
  • 1
  • 3