With [GitHub Pull Request #5772](https://github.com/nim-lang/Nim/pull/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](https://github.com/nim-lang/Nim/blob/devel/lib/pure/ospaths.nim#L546).
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](https://play.google.com/store/apps/details?id=com.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](https://forum.nim-lang.org/profile/Araq) says on
[IRC](https://irclogs.nim-lang.org/08-08-2017.html#10:34:31) 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`.