Compiling for Android

Moderators: Elijah, Igbo, timetraveller

kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 1 Week, 5 Hours, 25 Minutes ago)
Medals: 1
Topics: 71
Reputation: 2388
Location: North-Italy
Has thanked: 1185 times
Been thanked: 2951 times

Re: Compiling for Android

Post by kramnik »

I made one for the 64-bit version:
<?xml version="1.0" encoding="utf-8"?>
<enginelist>

<engine
name="Stockfish 15.1 64-bit"
filename="libstockfish_polyglot_15_1-64bit.so"
target="armeabi-v7a|arm64-v8a|x86|x86_64" />

</enginelist>
which produce a very large apk file (150 Megabytes) - maybe just x86_64 should work for the most of the Android devices, plus I've compiled only one
libstockfish_polyglot_15_1-64bit.so.

And I made one for the 32-bit version, I don't know if the syntax is correct:
<?xml version="1.0" encoding="utf-8"?>
<enginelist>

<engine
name="Stockfish 15.1 32-bit"
filename="libstockfish_polyglot_15_1-32bit.so"
target="armv7" />

</enginelist>
On my device this last apk doesn't install, it says "not compatible with your phone".

The 150 MBs 64-bit APK gets installed, though, and Stockfish Polyglot 64-bit works. Tested with Acid Ape GM edition.
Archimedes wrote: 12/02/2023, 10:36
kramnik wrote: 12/02/2023, 0:37 I compiled Stockfish with both Termux clang and Windows ndk clang, added it to the (before working) Texel project and modified enginelist.xml to use the new engines but it gave me error once loaded on Droidfish:
Post your enginelist.xml.
Archimedes

Android Engines Top Active Users
Forum Contributions
Points: 42 582,00 
Posts: 2059
Joined: 04/11/2019, 21:13
Status: Offline (Active 3 Hours, 46 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling for Android

Post by Archimedes »

If you want to provide support for all four architectures, then the jniLibs directory must contain all directories including all executables (e.g. libstockfish.so).

Code: Select all

arm64-v8a
armeabi-v7a
x86
x86_64
The engine.xml then looks like this in the case of Stockfish:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<enginelist>

    <engine
        name="Stockfish 15.1"
        filename="libstockfish.so"
        target="armeabi-v7a|arm64-v8a|x86|x86_64" />

</enginelist>
If you want to provide support for only one architecture (e.g. arm64-v8a), then the jniLibs directory must contain only one directory including one executable (e.g. libstockfish.so). That should be obvious. wink

Code: Select all

arm64-v8a
The engine.xml then looks like this in the case of Stockfish:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<enginelist>

    <engine
        name="Stockfish 15.1"
        filename="libstockfish.so"
        target="arm64-v8a" />

</enginelist>
Take care of your targets and use the right name for it. If it says "not compatible with your phone", test the native chess engine without the APK file first. Maybe the file is really not compatible.
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 1 Week, 5 Hours, 25 Minutes ago)
Medals: 1
Topics: 71
Reputation: 2388
Location: North-Italy
Has thanked: 1185 times
Been thanked: 2951 times

Re: Compiling for Android

Post by kramnik »

Archimedes wrote: 18/02/2023, 9:11 If you want to provide support for all four architectures, then the jniLibs directory must contain all directories including all executables (e.g. libstockfish.so).

Code: Select all

arm64-v8a
armeabi-v7a
x86
x86_64
I'm looking on Internet... armeabi-v7a stands for the old 32-bit processor, while arm64-v8a is for the newer 64-bit processor... At this point I have a question: are x86 and x86_64 targets for Android devices running on Intel?

Since I produced just two binaries - armv7 and armv8 - using make and the ndk compiler, I think I could exclude the targets x86 and x86_64 from the enginelist.xml file...
Archimedes

Android Engines Top Active Users
Forum Contributions
Points: 42 582,00 
Posts: 2059
Joined: 04/11/2019, 21:13
Status: Offline (Active 3 Hours, 46 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling for Android

Post by Archimedes »

kramnik wrote: 19/02/2023, 23:18 I'm looking on Internet... armeabi-v7a stands for the old 32-bit processor, while arm64-v8a is for the newer 64-bit processor... At this point I have a question: are x86 and x86_64 targets for Android devices running on Intel?
Yes, but I don't know if there are other processors with Android support.
kramnik wrote: 19/02/2023, 23:18 Since I produced just two binaries - armv7 and armv8 - using make and the ndk compiler, I think I could exclude the targets x86 and x86_64 from the enginelist.xml file...
Yes.
alex67a
Forum Contributions
Points: 6 000,00 
Posts: 24
Joined: 04/11/2019, 16:49
Status: Offline (Active 16 Hours, 14 Minutes ago)
Topics: 0
Reputation: 5
Been thanked: 15 times

Re: Compiling for Android

Post by alex67a »

Berserk 11.1 doesn't seem to work on my android...
Archimedes

Android Engines Top Active Users
Forum Contributions
Points: 42 582,00 
Posts: 2059
Joined: 04/11/2019, 21:13
Status: Offline (Active 3 Hours, 46 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling for Android

Post by Archimedes »

alex67a wrote: 21/02/2023, 14:21 Berserk 11.1 doesn't seem to work on my android...
Berserk was compiled entirely with Android NDK.

Maybe one of the following versions will work.
https://pixeldrain.com/l/tuYhKqqB
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 1 Week, 5 Hours, 25 Minutes ago)
Medals: 1
Topics: 71
Reputation: 2388
Location: North-Italy
Has thanked: 1185 times
Been thanked: 2951 times

Re: Compiling for Android

Post by kramnik »

Archimedes

Android Engines Top Active Users
Forum Contributions
Points: 42 582,00 
Posts: 2059
Joined: 04/11/2019, 21:13
Status: Offline (Active 3 Hours, 46 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling for Android

Post by Archimedes »

Yes, looks good and works so far. However, file version shows 1.08a18 when trying to install with an external file manager.
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 1 Week, 5 Hours, 25 Minutes ago)
Medals: 1
Topics: 71
Reputation: 2388
Location: North-Italy
Has thanked: 1185 times
Been thanked: 2951 times

Re: Compiling for Android

Post by kramnik »

Archimedes wrote: 28/02/2023, 23:23Yes, looks good and works so far. However, file version shows 1.08a18 when trying to install with an external file manager.
And what it means?
Archimedes

Android Engines Top Active Users
Forum Contributions
Points: 42 582,00 
Posts: 2059
Joined: 04/11/2019, 21:13
Status: Offline (Active 3 Hours, 46 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling for Android

Post by Archimedes »

You can think of it as cosmetics. Anyway, you should set the version number also correctly in the AndroidManifest.xml file (not only in enginelist.xml).

This version number is also displayed under Settings --> Apps --> <Your Chess Engine>. Could lead to irritation if it always says 1.08a18.
Kepcuk
I've been banned!
Points: 6 000,00 
Posts: 45
Joined: 01/02/2023, 13:20
Status: Offline (Active 10 Months, 3 Weeks, 6 Days, 6 Hours, 38 Minutes ago)
Topics: 9
Reputation: 18
1
Has thanked: 9 times
Been thanked: 51 times

Re: Compiling for Android

Post by Kepcuk »

slt make build ARCH=armv8 COMP=clang
Default net: nn-62ef826d1a6d.nnue
Downloading https://tests.stockfishchess.org/api/nn/nn-62ef826d1a6d.nnue

Config:
debug: 'no'
sanitize: 'no'
optimize: 'yes'
arch: 'armv8'
bits: '64'
kernel: 'Linux'
os: 'Android'
prefetch: 'yes'
popcnt: 'yes'
pext: 'no'
sse: 'no'
mmx: 'no'
sse2: 'no'
ssse3: 'no'
sse41: 'no'
avx: 'no'
avx2: 'no'
avx512: 'no'
vnni: 'no'
neon: 'yes'
native: 'no'
embed: 'no'

Flags:
CC: clang
CFLAGS: -Wall -std=c11 -pedantic -Wextra -Wshadow -m64 -D_DEFAULT_SOURCE -D_BSD_SOURCE -DNDEBUG -O3 -fexperimental-new-pass-manager -DIS_64BIT -DUSE_POPCNT -DUSE_NEON -DNUMA -DNNUE -DNNUE_SPARSE -flto
LDFLAGS: -lm -latomic -m64 -lnuma -Wall -std=c11 -pedantic -Wextra -Wshadow -m64 -D_DEFAULT_SOURCE -D_BSD_SOURCE -DNDEBUG -O3 -fexperimental-new-pass-manager -DIS_64BIT -DUSE_POPCNT -DUSE_NEON -DNUMA -DNNUE -DNNUE_SPARSE -flto

Testing config sanity. If this fails, try 'make help' ...

make ARCH=armv8 COMP=clang all
make[1]: Entering directory '/data/data/com.termux/files/home/Cfish/src'
clang -Wall -std=c11 -pedantic -Wextra -Wshadow -m64 -D_DEFAULT_SOURCE -D_BSD_SOURCE -DNDEBUG -O3 -fexperimental-new-pass-manager -DIS_64BIT -DUSE_POPCNT -DUSE_NEON -DNUMA -DNNUE -DNNUE_SPARSE -flto -c -o benchmark.o benchmark.c
clang-16: error: unknown argument: '-fexperimental-new-pass-manager'
make[1]: *** [<builtin>: benchmark.o] Error 1
make[1]: Leaving directory '/data/data/com.termux/files/home/Cfish/src'
make: *** [Makefile:866: build] Error 2
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 1 Week, 5 Hours, 25 Minutes ago)
Medals: 1
Topics: 71
Reputation: 2388
Location: North-Italy
Has thanked: 1185 times
Been thanked: 2951 times

Re: Compiling for Android

Post by kramnik »

Use the cecsa gcc.
Kepcuk wrote: 12/04/2023, 9:31 slt make build ARCH=armv8 COMP=clang
Default net: nn-62ef826d1a6d.nnue
Downloading https://tests.stockfishchess.org/api/nn/nn-62ef826d1a6d.nnue

Config:
debug: 'no'
sanitize: 'no'
optimize: 'yes'
arch: 'armv8'
bits: '64'
kernel: 'Linux'
os: 'Android'
prefetch: 'yes'
popcnt: 'yes'
pext: 'no'
sse: 'no'
mmx: 'no'
sse2: 'no'
ssse3: 'no'
sse41: 'no'
avx: 'no'
avx2: 'no'
avx512: 'no'
vnni: 'no'
neon: 'yes'
native: 'no'
embed: 'no'

Flags:
CC: clang
CFLAGS: -Wall -std=c11 -pedantic -Wextra -Wshadow -m64 -D_DEFAULT_SOURCE -D_BSD_SOURCE -DNDEBUG -O3 -fexperimental-new-pass-manager -DIS_64BIT -DUSE_POPCNT -DUSE_NEON -DNUMA -DNNUE -DNNUE_SPARSE -flto
LDFLAGS: -lm -latomic -m64 -lnuma -Wall -std=c11 -pedantic -Wextra -Wshadow -m64 -D_DEFAULT_SOURCE -D_BSD_SOURCE -DNDEBUG -O3 -fexperimental-new-pass-manager -DIS_64BIT -DUSE_POPCNT -DUSE_NEON -DNUMA -DNNUE -DNNUE_SPARSE -flto

Testing config sanity. If this fails, try 'make help' ...

make ARCH=armv8 COMP=clang all
make[1]: Entering directory '/data/data/com.termux/files/home/Cfish/src'
clang -Wall -std=c11 -pedantic -Wextra -Wshadow -m64 -D_DEFAULT_SOURCE -D_BSD_SOURCE -DNDEBUG -O3 -fexperimental-new-pass-manager -DIS_64BIT -DUSE_POPCNT -DUSE_NEON -DNUMA -DNNUE -DNNUE_SPARSE -flto -c -o benchmark.o benchmark.c
clang-16: error: unknown argument: '-fexperimental-new-pass-manager'
make[1]: *** [<builtin>: benchmark.o] Error 1
make[1]: Leaving directory '/data/data/com.termux/files/home/Cfish/src'
make: *** [Makefile:866: build] Error 2
Kepcuk
I've been banned!
Points: 6 000,00 
Posts: 45
Joined: 01/02/2023, 13:20
Status: Offline (Active 10 Months, 3 Weeks, 6 Days, 6 Hours, 38 Minutes ago)
Topics: 9
Reputation: 18
1
Has thanked: 9 times
Been thanked: 51 times

Re: Compiling for Android

Post by Kepcuk »

I tried it also. I cant and Archimedes doesnt looking for requests
LittleJoe

Top contribute Forum Engines Maker
Forum Contributions
Points: 14 078,00 
Posts: 327
Joined: 17/10/2020, 22:28
Status: Offline (Active 6 Days, 14 Hours, 50 Minutes ago)
Medals: 2
Topics: 5
Reputation: 506
Has thanked: 349 times
Been thanked: 671 times

Re: Compiling for Android

Post by LittleJoe »

Kepcuk wrote: 12/04/2023, 9:31 slt make build ARCH=armv8 COMP=clang
Default net: nn-62ef826d1a6d.nnue
Downloading https://tests.stockfishchess.org/api/nn/nn-62ef826d1a6d.nnue

Config:
debug: 'no'
sanitize: 'no'
optimize: 'yes'
arch: 'armv8'
bits: '64'
kernel: 'Linux'
os: 'Android'
prefetch: 'yes'
popcnt: 'yes'
pext: 'no'
sse: 'no'
mmx: 'no'
sse2: 'no'
ssse3: 'no'
sse41: 'no'
avx: 'no'
avx2: 'no'
avx512: 'no'
vnni: 'no'
neon: 'yes'
native: 'no'
embed: 'no'

Flags:
CC: clang
CFLAGS: -Wall -std=c11 -pedantic -Wextra -Wshadow -m64 -D_DEFAULT_SOURCE -D_BSD_SOURCE -DNDEBUG -O3 -fexperimental-new-pass-manager -DIS_64BIT -DUSE_POPCNT -DUSE_NEON -DNUMA -DNNUE -DNNUE_SPARSE -flto
LDFLAGS: -lm -latomic -m64 -lnuma -Wall -std=c11 -pedantic -Wextra -Wshadow -m64 -D_DEFAULT_SOURCE -D_BSD_SOURCE -DNDEBUG -O3 -fexperimental-new-pass-manager -DIS_64BIT -DUSE_POPCNT -DUSE_NEON -DNUMA -DNNUE -DNNUE_SPARSE -flto

Testing config sanity. If this fails, try 'make help' ...

make ARCH=armv8 COMP=clang all
make[1]: Entering directory '/data/data/com.termux/files/home/Cfish/src'
clang -Wall -std=c11 -pedantic -Wextra -Wshadow -m64 -D_DEFAULT_SOURCE -D_BSD_SOURCE -DNDEBUG -O3 -fexperimental-new-pass-manager -DIS_64BIT -DUSE_POPCNT -DUSE_NEON -DNUMA -DNNUE -DNNUE_SPARSE -flto -c -o benchmark.o benchmark.c
clang-16: error: unknown argument: '-fexperimental-new-pass-manager'
make[1]: *** [<builtin>: benchmark.o] Error 1
make[1]: Leaving directory '/data/data/com.termux/files/home/Cfish/src'
make: *** [Makefile:866: build] Error 2
Clang-16 very clearly tells you what the problem is.
Therefore, just delete this 'problem' in the Makefile.
Or wait for Archimedes or PM him, as I've already told you some time ago. wa_ll
SkyNet

Top contribute Forum Engines Maker Book Maker
Forum Contributions
Points: 33 208,00 
Posts: 326
Joined: 11/11/2022, 1:55
Status: Offline (Active 19 Hours, 28 Minutes ago)
Medals: 3
Topics: 6
Reputation: 3154
Location: 3th dimension.
Has thanked: 5209 times
Been thanked: 2368 times

Re: Compiling for Android

Post by SkyNet »

Kepcuk wrote: 12/04/2023, 9:31
make ARCH=armv8 COMP=clang all
make[1]: Entering directory '/data/data/com.termux/files/home/Cfish/src'
clang -Wall -std=c11 -pedantic -Wextra -Wshadow -m64 -D_DEFAULT_SOURCE -D_BSD_SOURCE -DNDEBUG -O3 -fexperimental-new-pass-manager -DIS_64BIT -DUSE_POPCNT -DUSE_NEON -DNUMA -DNNUE -DNNUE_SPARSE -flto -c -o benchmark.o benchmark.c
clang-16: error: unknown argument: '-fexperimental-new-pass-manager'
make[1]: *** [<builtin>: benchmark.o] Error 1
make[1]: Leaving directory '/data/data/com.termux/files/home/Cfish/src'
make: *** [Makefile:866: build] Error 2
Try to delete flags from Makefile -> "-fexperimental-new-pass-manager" and "-DNUMA" (NUMA was never supported on android).
Post Reply

Return to “Programming, Technical Discussions, Chess related questions etc.”