It appears that in order to use a native C library on Android, you need to have it compiled into .so
and .a
library files. How do you do that on Windows? It seems that it's only possible to compile .lib
and .dll
files. Does that mean you can't do Android development with the NDK on Windows?

- 837
- 2
- 11
- 22
-
1Use [android-ndk](https://developer.android.com/ndk/guides/cmake). – Dmitrii Z. Sep 16 '18 at 18:17
-
1Why do you open 3 separate questions for the same problem? This doesn't help you or others. The best practice here on SO would be, instead, to open a bounty on the old [question](https://stackoverflow.com/q/51159214/192373) which did not receive deserved attention. Now you shouldn't be surprised that the quality of answers you get is low. – Alex Cohn Sep 16 '18 at 19:42
-
These were 3 separate problems – Filip Petrovic Sep 16 '18 at 20:15
-
But yes, all 3 for the same thing. But they are different problems – Filip Petrovic Sep 16 '18 at 20:15
-
1It is a common question for people newly coming to Android, felt it is a valid one. – Gerry Sep 20 '18 at 16:06
1 Answers
Does that mean you can't do Android development with the NDK on Windows?
No, you can build Android apps with native C code on windows.
.so and .a files are compiled library formats used primarily by Linux based operating systems. Android uses Linux kernel. So it required the native libraries to be compiled to .so format for dynamic linking and to .a format for static linking.
So you need a cross compiler
to compile a library into Linux compatible format in Windows. Also your normal Visual Studio compiler might only compile to X-64
machine code. In order for the library to be usable in all CPU architectures that Android supports (most Android devices have ARM CPUs), you need the library to be compiled to ARM instruction set machine codes.
You can set it up all by yourself using GNU-C compiler and CMake. But that's cumbersome.
Fortunately, Android NDK have everything set up for you. Everything you need is already provided and configured in Android NDK (Native Development Kit).
See developer guide for Android NDK here https://developer.android.com/ndk/guides/

- 1,682
- 13
- 23
-
Hello. Would that mean, I can try to link .lib files directly in the CMakeLists.txt file in an Android NDK project ? Can you a bit more specific about how to transform a .lib file to .a file and so on ? – Rathnavel Dec 10 '19 at 05:50