With GitHub Pull Request #5772 merged, proper support for the Android operating system is coming to the next version of Nim.
Yes, Android is very similar to linux, but in some cases it's doing its own thing. That's why we introduced an own OS symbol for Android. That means that you can use the --os:android option to cross-compile for android. For example to compile koch:
nim compile --os:android koch
This also means that you can use the following to create code paths specific for android:
when defined(android): echo "Hello from Android"you can see this being used in the standard library, for example in the implementation of getTempDir on GitHub.
However, cross-compiling for android will only work, if you have an android cross-compiler (for example from the Android NDK) and as with all cross-compilers you'll have to set that up with the correct settings in your own nim.cfg
Alternatively, you can also install an app called termux on your android phone (or emulator) which is a terminal for Android and provides apt-get like packages. In there you'll have to run the following command to install the Android-Termux prerequisites for compiling Nim from source:
apt update apt install libandroid-glob-dev libandroid-glob git clang nodejs pcre pcre-dev libsqlite --yes
Araq says on IRC that he'll update the csources repository tonight, so you'll be able to compile Nim from source in the same way as you would do on any other OS. Please note though that Android is a little bit annoying in that it does not report itself as Android to build.sh. Because of that replace ./build.sh with sh build.sh --os android to build nim from the csources repository.
This will create the nim Android shell executable nim in the bin folder just as you'd expect. And running nim --version should print the Nim version number. It should also specify Android as the operating system and, depending on your phone CPU architecture, print either arm, arm64 or i386.
Special thanks to stisa for doing the initial work in identifying where we needed to modify the standard library to get the very first nim build on Android.
Thanks also to TiberiumN for helping me test run nim on 64-bit ARM.