Search code examples
androidstatic-librariesstatic-linkingabi

How to combine android static libraries with different ABIs?


I have built android static library 4 times, each with different ABI. So I have this files:

someLib_armeabi-v7a.a
someLib_arm64-v8a.a 
someLib_x86.a 
someLib_x86_64.a  

How I can (if its possible) combine them into one library which will contain all ABIs?

Thanks in advance.


Solution

  • You can not.

    These are files containing machine code, each for a different CPU architecture, and there is no file format that allows you to pack them all together and let the loader decide what to load.

    Also, note that *.a files are static libraries and can not be used directly. You need to link them in to a dynamic library - a *.so file before they can be added to your app.

    On Android, when building an APK, native libraries are packaged in separate folders inside the APK (which is actually a ZIP) named after the ABI like so: /lib/arm64-v8a/someLib.so or /lib/armeabi-v7a/someLib.so

    This packaging is done automatically by the build system, provided you configure your project correctly, and it is necessary for the OS on the device to find and use the library.

    It is however recommended by Google to use "App bundles" that will automatically split your APK to several different APKs optimized per device architecture to reduce both storage and download bandwidth for your users.

    https://developer.android.com/guide/app-bundle