Building Crystal in Android

I’m trying to build my crystal program with

crystal build main.cr --target x86_64-linux-android

for x86_64 android, but it’s giving me a error like this:

There was a problem expanding macro ‘macro_518336204592’ Code in /data/data/com.termux/files/usr/share/crystal/src/exception/call_stack/libunwind.cr:1:1

1 | {% unless flag?(:win32) %} ^

Called macro defined in /data/data/com.termux/files/usr/share/crystal/src/exception/call_stack/libunwind.cr:1:1

1 | {% unless flag?(:win32) %}

Which expanded to:

1 | > 2 | require “c/dlfcn”

     ^

Error: can’t find file ‘c/dlfcn’

i also tried to compile it to LLVM IR and then compile using Android NDK Prebuilt CLANG ( It didn’t seem like something that would work, but it wouldn’t hurt to try. ) and well, same error.

x86-64 Android isn’t supported, only AArch64 Android (and you should not have to cross-compile anything when you are already on Termux)

Hmm, very sad😔, I really wanted to use Crystal in my project, I’ll have to keep using C, Anyway, Thanks for replying

Why would you explicitly need x86-64? Apart from running an Android emulator on an x86-64 host I can’t think of any real applications of Android outside AArch64.

i need build to x86 x86_64 , ameabi and aarch64

cause jniLibs requires it

`…/c/cdroid $ ls -R android/app/src/main/jniLibs

android/app/src/main/jniLibs:

arm64-v8a armeabi-v7a x86 x86_64

android/app/src/main/jniLibs/arm64-v8a: libcdroid.so

android/app/src/main/jniLibs/armeabi-v7a: libcdroid.so

android/app/src/main/jniLibs/x86: libcdroid.so

android/app/src/main/jniLibs/x86_64: libcdroid.so

btw that’s how i’m compiling my project (in C)

i use NDK

Well you only build for the arm64-v8a ABI. The x86 and armeabi-v7a ABIs are even less relevant these days.

It looks like the other build systems assume all ABis by default and you have to filter them explicitly: https://developer.android.com/ndk/guides/abis#gc

makes sense, i guess i’ll do it so

1 Like