Compiling native code without using the NDK?

Hi everyone! First time making a topic, I hope I picked the right category. I got a feeling this is a really stupid question… but I’ve been thinking and searching for this for too long. And now that I have the chance to ask people skilled in this area, who probably have had similar ideas (and ideals), I’m going to accept looking stupid see where this leads.

Debian’s Android Tools packaging team has put great effort into turning the android SDK into independent official packages (not a small accomplishment!), making it possible to build apps written in Java. But the NDK is still missing. I know about Android Rebuilds, but I would still like to limit the software I use to official distro packages.

But… just like the SDK, many parts of the NDK are existing software. So would it be possible to use the normal tools used for cross compiling (the same gcc used to target gnu/linux on the same architecture as the android system) to compile C code to include in an app (written in Java and built using the android sdk parts from debian)? I’ve heard people did experiment with this to build executables (run through a terminal in android) before there was an NDK, and I did see Guix running on Android recently. But I haven’t found much information on doing this, and no info on doing this to compile native code to include in an actual app.

So my questions are: Would this be possible? Has anyone done this? If so, is there some reference/demo/guide? Would there be any significant disadvantage from doing this? And would such an app be accepted in the F-Droid repo (which is buillt using the official NDK and SDK)?

Thanks for any response. And keep up the good work on F-Droid!

2 Likes

In short (and more technical): I’m wondering if one can use, say, arm-linux-gnueabi-gcc to compile a .so or .a and include it in an app like it’s been built from the NDK. I know it’s possible to build (static) programs this way, but would it work for a native library for an app? Or will this not work? Maybe using the “androideabi” abi is required?

I probably should have said this from the start. I hope it’s ok that I wrote this as a reply to myself.

It’s a Debian VM, the build server, you can build anything.

How do you build your app now? You can repro the same setup… I guess.

Thanks for your feedback, it means a lot! (and sorry for the late reply!)

So the F-Droid part seems possible (simply apt-get in the build metadata). Now the big question is if something like arm-linux-gnueabi-gcc will work.

It seems compiling simple C code to .a or .so might work. But bionic and linking to more libraries might be a problem. I was hoping to link and use things like EGL, GLES.

How do you currently build? Explain…

Thanks for your reply. First some background: I got a old project (GPL3, C/C++, Using ODE, SDL, OpenGL, … and built using autoconf) that I’ve been wanting to get back to, redesign and also port to Android (specifically for F-Droid, not the google store). It currently supports GNU/Linux, other GNU variants, BSD:s, Windows, Mac and a few others.

So it currently doesn’t build against android. But before I try to port it I wanted to see if it’s feasible to rely entirely on debian packages. The android sdk is available, but the NDK is not. Since I’m free to design/port from scratch, maybe there are ways to design the “native code” around the fact that I would use the normal gcc (like arm-linux-gnueabi-gcc) instead of the NDK tools?

I’m also trying to see if I can get GNU Guile compiled and running as “native code” in an android app (I’m planing on using it in my project, if it’s portable enough). I know installing GUIX on android includes guile, but that is using proper elf binaries, placed and run directly from the filesytem outside the VM stuff, so not surprising it works and not quite what I’m looking for (unless I can still do GLES calls from outside the VM?)

I would suggest doing some experiments with simple “native” programs to test the feasibility of your idea. Although my instinct tells me that you will need the compilers from the NDK to build a fully native application, it seems that people have managed to build static executables using the gnueabi compilers (see this Stack Overflow question).

I don’t know how well you can integrate an application built in this way with the Android system it is running on.

Another approach might be to build the application using tools running in something like Termux and take advantage of its add-ons to build a user interface, though it might be a bit more limited than a normal application.