0

How to create .a file instead .so from c source using android studio?

If it is possible , then also I want want to know how to load them and pros and cons of using .a file instead .so

LaraFlow
  • 352
  • 5
  • 15

1 Answers1

2

Android relies on Java's System.loadLibrary() to load native code. This call uses the dl* family of functions to load a dynamic library (commonly associated with extension .so). The dynamic library can specify other libraries as its dependencies, which will be loaded in turn. After opening the library, the JVM probes it for functions with specially crafted names, which are bound to the corresponding Java methods.

By contrast, a .a file is a static library. It is simply an archive of object files (.o) that are meant for consumption by static linking when compilation.

To answer your question: yes, you could alter your CMakeLists.txt to create static libraries, but eventually you will have to link these together into a dynamic .so in order to load it in Android. See for example the bottom part of this answer where a number of prebuilt static libraries are linked together with a single .cpp file to produce a dynamic library.

Botje
  • 26,269
  • 3
  • 31
  • 41