Page 1 of 3
building for Android
Posted: Wed Apr 19, 2017 3:56 pm
by jdart
I have put some effort recently into getting Arasan to run on Android. I know Jim Ablett among others have been able to build and run it on Android in the past but the makefile I distribute doesn't support cross-compilation, so I am trying to fix that. So far I have only been trying this on a Linux host.
I downloaded the NDK and followed the instructions to set up a standalone toolchain. I used this command:
$NDK/build/tools/make_standalone_toolchain.py --install-dir=/home/jdart/chess/chess/android-toolchain-clang --arch arm --api 9 --stl=libc++
And then I put the toolchain bin directory on the PATH. I understand that with the latest NDK "clang" is the preferred compiler. I have done a little hacking on the code and Makefile to make it build. My latest changes are here:
https://github.com/jdart1/arasan-chess/tree/android2
If I issue the command:
make CC=clang android-arm
from the src directory, everything builds and I get an ARM executable. But this does not run when I transfer it to my Android phone (Samsung Galaxy S7) and try it with Chess for Android. I just get the message "engine exits."
Aart Biks' page on Chess for Android (
http://www.aartbik.com/MISC/uchess.html) suggests that the engine needs to be statically linked. However, all my attempts to do that have failed with errors at compile or link time. I have tried various combinations of -static, -static-libc++ and -static-libgcc.
I am kind of stuck now. Any suggestions?
--Jon
Re: building for Android
Posted: Wed Apr 19, 2017 4:29 pm
by mhull
jdart wrote:I have put some effort recently into getting Arasan to run on Android. I know Jim Ablett among others have been able to build and run it on Android in the past but the makefile I distribute doesn't support cross-compilation, so I am trying to fix that. So far I have only been trying this on a Linux host.
I downloaded the NDK and followed the instructions to set up a standalone toolchain. I used this command:
$NDK/build/tools/make_standalone_toolchain.py --install-dir=/home/jdart/chess/chess/android-toolchain-clang --arch arm --api 9 --stl=libc++
And then I put the toolchain bin directory on the PATH. I understand that with the latest NDK "clang" is the preferred compiler. I have done a little hacking on the code and Makefile to make it build. My latest changes are here:
https://github.com/jdart1/arasan-chess/tree/android2
If I issue the command:
make CC=clang android-arm
from the src directory, everything builds and I get an ARM executable. But this does not run when I transfer it to my Android phone (Samsung Galaxy S7) and try it with Chess for Android. I just get the message "engine exits."
Aart Biks' page on Chess for Android (
http://www.aartbik.com/MISC/uchess.html) suggests that the engine needs to be statically linked. However, all my attempts to do that have failed with errors at compile or link time. I have tried various combinations of -static, -static-libc++ and -static-libgcc.
I am kind of stuck now. Any suggestions?
--Jon
FWIW, I had trouble cross-compiling with -static for m68k with some libs that required the -lm switch (when not compiling -static). -static and -lm seemed to be incompatible. Finding and including the source for "-lm modules" fixed this.
Re: building for Android
Posted: Wed Apr 19, 2017 5:47 pm
by Sery
I've had negative experience with cross-compiling for Android, too. The only way I found is using Android app CCTools with key -static-libstdc++ in the makefile.
Re: building for Android
Posted: Wed Apr 19, 2017 6:38 pm
by Patrice Duhamel
For Android 5 and more recent, add -fPIE to compiler flags and and -fPIE -pie to linker flags.
In previous version of Cheese it worked with a static linked version, now I'm using position independant executables.
I'm using Cmake + Android Cmake toolchain :
https://github.com/taka-no-me/android-cmake
Re: building for Android
Posted: Wed Apr 19, 2017 9:09 pm
by tttony
I'm on windows but this works for me, I have an old NDK
Files
android-build.bat
/Skiull/jni/Application.mk
/Skiull/jni/Android.mk
android-build.bat
Code: Select all
@ECHO OFF
SET NDK=F:\android-ndk-r8e-windows-x86_64\android-ndk-r8e
SET CURRDIR=%~dp0
SET NDK_PROJECT_PATH=%CURRDIR:~0,-1%\Skiull
IF EXIST android.log DEL android.log
CALL %NDK%\ndk-build.cmd -d V=1 NDK_LOG=1 > android.log
%NDK% variable it's de android ndk directory, ndk-build.cmd must be there
%NDK_PROJECT_PATH% it's where the *.c files project are
jni/Application.mk
Code: Select all
APP_ABI := all
APP_PLATFORM := android-14
APP_ABI it's the cpu architecture, all=armeabi,armeabi-v7a,mips,x86
APP_PLATFORM it's the android api: android-14 (Android 4.0 ICS)
jni/Android.mk
Code: Select all
LOCAL_PATH := $(NDK_PROJECT_PATH)
include $(CLEAR_VARS)
LOCAL_MODULE := skiull-$(TARGET_PLATFORM)-$(TARGET_ARCH_ABI)
LOCAL_SRC_FILES := main.c attack.c board.c debug.c fen.c hash.c see.c init.c magicmoves.c move.c movegen.c perft.c uci.c utils.c bitboard.c eval.c search.c
LOCAL_C_INCLUDES += $(NDK_PROJECT_PATH)
include $(BUILD_EXECUTABLE)
I think it's self explanatory code here
Read more here
https://developer.android.com/ndk/guides/ndk-build.html
Proof:
Re: building for Android
Posted: Wed Apr 19, 2017 10:07 pm
by abik
jdart wrote:Aart Biks' page on Chess for Android (
http://www.aartbik.com/MISC/uchess.html) suggests that the engine needs to be statically linked. However, all my attempts to do that have failed with errors at compile or link time. I have tried various combinations of -static, -static-libc++ and -static-libgcc.
I am kind of stuck now. Any suggestions?
Did you have a look at this
older thread?
It would help to see the actual error message (I realize CfA just shows "engine exits"; and yes, I still want to display more informative messages there, but it is not straightforward to extract that).
Running this in a command line shell on the device would show more details (using adb). I can help you with that, although I don't have your specific device.
Re: building for Android
Posted: Wed Apr 19, 2017 11:53 pm
by jdart
I am going to try a PIC executable because at least I can get that to build.
But the actual error I am getting now is "Permission denied". I copied the file to sdcard/My Documents and it appears that strips off the execute permissions. And the phone is not rooted so I can't change them.
It appears adb can set permissions so maybe I need to install that.
--Jon
Re: building for Android
Posted: Thu Apr 20, 2017 12:09 am
by abik
jdart wrote:But the actual error I am getting now is "Permission denied". I copied the file to sdcard/My Documents and it appears that strips off the execute permissions.
sdcards are typically noexec, so that won't work; do you have a binary to share, or do you prefer to keep that private until it works?
Re: building for Android
Posted: Thu Apr 20, 2017 12:38 am
by jdart
I put a copy of the latest here:
https://www.arasanchess.org/arasanx-android-arm
It is built from the branch I mentioned, except -fPIE has been added to the flags.
--Jon
Re: building for Android
Posted: Thu Apr 20, 2017 12:41 am
by abik
jdart wrote:It is built from the branch I mentioned, except -fPIE has been added to the flags.
Hmm, does not look quite PIE...
Code: Select all
# ./arasanx-android-arm
"./arasanx-android-arm": error: Android 5.0 and later only support position-independent executables (-fPIE).
Details:
Code: Select all
./arasanx-android-arm: ELF executable, 32-bit LSB arm, dynamic (/system/bin/linker), for Android 9, built by NDK r14b (3816874)