Older Android devices can be had for a song, and in many cases are still packing considerable computational power. With built in networking, a battery, and a big touch screen, they could easily take the place of a Raspberry Pi and external display in many applications. As it so happens, Google has made it very easy to develop your own Android software. There’s only one problem: you’ve got to do it in Java.
Looking to get away from all that bloat and overhead, [CNLohr] set out to see what it would take to get 100% C code running on an Android device. After collecting information and resources from the deepest and darkest corners of the Internet, he found out that the process actually wasn’t that bad. He’s crafted a makefile which can be used to get your own C program up and running in seconds.
We mean that literally. As demonstrated in the video after the break, [CNLohr] is able to compile, upload, and run a C Android program in less than two seconds with a single command. This rapid development cycle allows you to spend more time on actually getting work done, as you can iterate through versions of your code almost as quickly as if you were running them on your local machine.
[CNLohr] says you’ll still need to have Google’s Android Studio installed, so it’s not as if this is some clean room implementation. But once it’s installed, you can just call everything from his makefile and never have to interact with it directly. Even if you don’t have any problem with the official Android development tools, there’s certainly something to be said for being able to write a “Hello World” that doesn’t clock in at multiple-megabytes.
32 thoughts on “Writing Android Apps In C, No Java Required”
Noice, might have to play with this to see if I can get myself a port of DOSbox that I don’t hate… they all do some (un)helpful keyboard tomfoolery, among other issues. Also need latest version to fix incompatibility with a game I like.
Good stuff !
This is similar to the technique used to write system apps in AOSP. If you look at the AOSP source code you will see many examples.
Interesting! Might I use it one day.
You don’t actually need Android Studio, you can install the NDK from a terminal: https://github.com/cnlohr/rawdrawandroid#steps-for-gui-less-install-windows-wsl
There’s also Boden.io for cross platform C++ based development that works on both Android and iOS the same way, and hopefully it has documentation.
Hmm, interesting post, thanks.
Unfortunately I’m so habituated & practiced as in dead easy to visualise too in Basic, Pascal or 8 bit assembler like z80, 8051 series still current from silabs & occasional Motorola 68705 series.
So is there a way to write “apps” in basic or Pascal preferably compiled, though interpreter tolerable ?
This looks surprisingly possible. freepascal has an LLVM output, which can target clang, the compiler used for building these android apps. So… while you would need a little bit of C glue code, it looks like almost everything is achievable in Pascal.
Hmm, a practical line of progress, good to hear, I guess I can deal with some C, though have to update my acronyms as so many popping up making my head spin, seems I do expect I need to get up to date on a few related paradigms, something to review for sure thanks :-)
If Pascal includes Delphi, then you can give Embarcadero a try:
Tah akashu, didn’t know about this, thanks :-)
Yes. Lazarus and Freepascal can build Android Apps.
Cool thanks, much to review, time to clear all the electronic clutter off my office desk, ugh.
Think the most admin onerous task is going through all the os function interface objects, eek, cheers
Research Basic4Android, also known as B4A.
It’s very lightweight.
Termux removed support for older devices, you can actually have your compiler on the phone itself, no need of SDK and cross-compilers, which always have their issues.
But you can install older termux versions and use archived packages.
Weird. I had no idea this level was possible. It looks like he’s basically using JNI for all the interfaces, but without providing his own Java code for the wrapper. I’m not sure I like it but it definitely opens some possibilities.
Indeed that’s how it rolls. Instead of using JNI to call Java glue code – just call it.
What bothers me is that if the battery is dead you cant have an autostart when you supply the phone.
Why not? Add it to the manifest
Curious if graalvm which is a similar CM that allows cross compilation of C/C++ I believe via llvm as well would be another option.
Probably C or Java are too complex and too low to make applications, Python would be better.
i could never get used to python. its just too wierd. take away my curly braces and im completely lost. im fine with c and c++ though. only interpreted language i really like to use is lua. its really great at making fast and dirty gui apps for talking to arduinos. as its very good at text processing io over a serial terminal (pattern matching features in the strings library are awesome).
I initially had a hard time with Python being a C/C++/C# programmer. And the lack of effective in-line debugging like VS has was a real problem for me. I also thought the VS gui generation is leagues beyond Python. But I got used to it. Just takes a little longer to debug code.
If you want this speed but with a higher level language, check out Flutter!
please port doom lol
Has already been done … a lot.
how about using the camera? internet access? wifi? many many requests are on the list …
It makes me very happy that someone has done this. Android development stinks because Java (Also known as the second least efficient programming language in existence, second only to Befunge-93) and using C/C++ will be great!
I can’t wait for someone to reverse-engineer the Billing API for this…
well tickle me pink! I’ve done C for over 20 years, mainly doing gui stuff with GTK etc. but this looks very interesting and very promising. I have questions…. one, would a project of this be able to use glib? I don’t know, just a question. I’m still going to use this and yes I code for ESP8266! got a cool project working right now, on using its networking abilities with arduCam. I am looking forward to using this in my project. ;)
Crikey! No wonder Android apps are so slow and massive if they’re written in Java!
Does the same apply to web browsers, e.g. Android Chrome, FFox etc?
Please be kind and respectful to help make the comments section excellent. (Comment Policy)