Cross Compiling for Android NDK from Windows

1,429 views
Skip to first unread message

Rathnavel Sankaralingam

unread,
Dec 26, 2019, 12:13:03 PM12/26/19
to android-ndk

I am trying to cross-compile an API that we developed in Windows which is our only dev environment at the moment. The API has few third party dependencies which are as well Windows based .libs and .dlls. In Windows, when I use the API libraries we compile it statically and generate .libs and include and link them for the apps I want to create using the API.

Now I have a situation where I want to use these libraries in a very basic Android App, and the idea is to use Android NDK with CMake. I understand the API needs to be cross compiled for ARM, but its quite dizzying because most of the options/tutorials available are Linux based. [Complete Noob on Android here]

I found LLVM with Clang and some python tools that come with NDK to be useful for cross-compiling on Windows. I was able to compile a file using these and I got an a.out file. But that was just a single CPP file, whereas I need to compile several files together into a .a file (static lib) which I can then include in my CMake in NDK. So I need the equivalents for .libs on windows. (ObjGL.lib -> ObjGL.a, Shape.lib -> Shape.a etc)

My question is should I try to build something like a makefile to get a .a file or what is the best way to do this from Windows itself? Any pointers/links would be appreciated. TIA!

Shahriar Vaghar

unread,
Dec 29, 2019, 12:02:20 PM12/29/19
to andro...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/e39eb252-d200-4dbc-97d7-c7ced1ef8f0d%40googlegroups.com.

Rathnavel Sankaralingam

unread,
Jan 2, 2020, 10:49:24 AM1/2/20
to android-ndk

I am trying to cross-compile an API that we developed in Windows which is our only dev environment at the moment. The API has few third party dependencies which are as well Windows based .libs and .dlls. In Windows, when I use the API libraries we compile it statically and generate .libs and include and link them for the apps I want to create using the API.

Now I have a situation where I want to use these libraries in a very basic Android App, and the idea is to use Android NDK with CMake. I understand the API needs to be cross compiled for ARM, but its quite dizzying because most of the options/tutorials available are Linux based. [Complete Noob on Android here]

I found LLVM with Clang and some python tools that come with NDK to be useful for cross-compiling on Windows. I was able to compile a file using these and I got an a.out file. But that was just a single CPP file, whereas I need to compile several files together into a .a file (static lib) which I can then include in my CMake in NDK. So I need the equivalents for .libs on windows. (ObjGL.lib -> ObjGL.a, Shape.lib -> Shape.a etc)

My question is should I try to build something like a makefile to get a .a file or what is the best way to do this from Windows itself? Any pointers/links would be appreciated. Thanks in advance!


Chris Browet

unread,
Jan 3, 2020, 3:49:09 AM1/3/20
to android-ndk
Easiest way is probably to use CMake. Here is a simple CmakeList.txt that produces a static lib from a bunch of cpp: https://github.com/xbmc/libandroidjni/blob/master/CMakeLists.txt
See https://developer.android.com/ndk/guides/cmake on how to use cmake for android.

Re platform, easiest is to do it from a linux VM, ofc, but you can also use Windows 10 Linux subsystem.

Chris Browet

unread,
Jan 3, 2020, 4:11:40 AM1/3/20
to android-ndk
Actually, as Android Studio supports CMake, you can do it directly from there, by altering you build.gradle, without ever touching linux ;)

Dan Albert

unread,
Jan 6, 2020, 12:32:33 PM1/6/20
to android-ndk
There are a handful of docs covering different build systems on our docs site. You probably want the one for cmake: https://developer.android.com/ndk/guides/cmake

Reply all
Reply to author
Forward
0 new messages