Compiling for Android

Moderators: Elijah, Igbo, timetraveller

Archimedes

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

Re: Compiling for Android

Post by Archimedes »

To the short descriptions for C and C++ I have now also added a short note for Rust to the wiki.

https://sourceforge.net/p/chess-engines-for-android/wiki/home/
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 6 Days, 14 Hours, 20 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 »

Still, I see no tutorials about how to compile the Stockfish source into OEX (APK installer). With the newest Android releases there is a restriction which many chess apps adopted, so one cannot just compile the source to binary and use it to said apps anymore.
Archimedes wrote: 17/01/2023, 21:13 To the short descriptions for C and C++ I have now also added a short note for Rust to the wiki.

https://sourceforge.net/p/chess-engines-for-android/wiki/home/
Archimedes

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

Re: Compiling for Android

Post by Archimedes »

kramnik wrote: 31/01/2023, 22:33 Still, I see no tutorials about how to compile the Stockfish source into OEX (APK installer). With the newest Android releases there is a restriction which many chess apps adopted, so one cannot just compile the source to binary and use it to said apps anymore.
There is already a ready-made and documented Java library that can do this. You don't have to reinvent the wheel.

https://github.com/gkalab/chessenginesupport-androidlib

To see how it works, there is also an example for Stockfish.

Another example can be found here:
https://github.com/peterosterlund2/texelapp

And yet another example, adapted to a newer version of Android Studio, can be found here:
https://sourceforge.net/p/chess-engines-for-android-oex/wiki/home/
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 6 Days, 14 Hours, 20 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 exactly followed what is written on this page: https://sourceforge.net/p/chess-engines-for-android-oex/wiki/how-to-create-an-apk-file-for-texel/
This short description assumes basic knowledge of Android Studio.

A current project directory for Texel is attached. This project use the chess engine support library for Android from https://github.com/gkalab/chessenginesupport-androidlib and has been adapted to the latest version of Android Studio.

First, change the string "yourname" to your name in the following files:

texelChessEngine\build.gradle
texelChessEngine\src\main\AndroidManifest.xml
texelChessEngine\src\main\java\org\yourname\chess\texel\MainActivity.java
texelChessEngine\src\main\java\org\yourname\chess\texel\TexelProvider.java
Finally, change the following directory to your name:

texelChessEngine\src\main\java\org\yourname
Do this job, before you load the project into Android Studio.

Load the project into Android Studio and generate a signed APK file.
But once the project is loaded in Android Studio (the new Electric Eel version) I get the following error:
Task 'wrapper' not found in project ':texelChessEngine'.

* Try:
> Run gradle tasks to get a list of available tasks.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.


----------------------------


Archimedes wrote: 01/02/2023, 9:43
kramnik wrote: 31/01/2023, 22:33 Still, I see no tutorials about how to compile the Stockfish source into OEX (APK installer). With the newest Android releases there is a restriction which many chess apps adopted, so one cannot just compile the source to binary and use it to said apps anymore.
There is already a ready-made and documented Java library that can do this. You don't have to reinvent the wheel.

...

And yet another example, adapted to a newer version of Android Studio, can be found here:
https://sourceforge.net/p/chess-engines-for-android-oex/wiki/home/
Archimedes

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

Re: Compiling for Android

Post by Archimedes »

The description assumes a working Android Studio.

If you download the attachment ("Texel_Chess_Engine.zip"), do nothing. Open the project as it is in Android Studio. Do errors still appear?
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 6 Days, 14 Hours, 20 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 »

You mean that I don't have to decompress it?
Archimedes wrote: 04/02/2023, 10:19 The description assumes a working Android Studio.

If you download the attachment ("Texel_Chess_Engine.zip"), do nothing. Open the project as it is in Android Studio. Do errors still appear?
Archimedes

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

Re: Compiling for Android

Post by Archimedes »

kramnik wrote: 05/02/2023, 22:52 You mean that I don't have to decompress it?
Of course, you have to extract the zip archive first.
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 6 Days, 14 Hours, 20 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 »

Then I've done everything properly. At least I think so: I compiled and ran the basic Android Studio project and ig ran perfectly. Then I decompressed the Texel zip file and I tried to start the project by opening the "Texel Chess Engine" folder with the Android Studio Select Project dialog window.
Archimedes wrote: 06/02/2023, 8:25
kramnik wrote: 05/02/2023, 22:52 You mean that I don't have to decompress it?
Of course, you have to extract the zip archive first.
Archimedes

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

Re: Compiling for Android

Post by Archimedes »

I don't know what the problem is. Explain step by step what you are actually doing.

If I load the project into Android Studio (takes a little time the first time), don't change anything and then immediately create a signed APK file (Build --> Generate Signed Bundle / APK... --> APK), I don't get an error message. I get an installer for the Texel Chess Engine.
superbatil
Forum Contributions
Points: 14 010,00 
Posts: 76
Joined: 24/02/2022, 11:23
Status: Offline (Active 2 Weeks, 1 Hour, 57 Minutes ago)
Topics: 0
Reputation: 17
Has thanked: 1 time
Been thanked: 51 times

Re: Compiling for Android

Post by superbatil »

Im using Termux on android for compiling.
"command use"

Code: Select all

make -j2 profile-build ARCH=armv8 COMP=clang blas=yes
"malloc error"

Code: Select all

misc.cpp:659:15: error: use of undeclared identifier '_mm_malloc'
    void* p = _mm_malloc(size, align);
              ^
1 warning and 1 error generated.
make[2]: *** [<builtin>: misc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
1 warning generated.
make[2]: Leaving directory '/data/data/com.termux/files/home/Stockfish_nodchip/src'
make[1]: *** [Makefile:903: clang-profile-make] Error 2
make[1]: Leaving directory '/data/data/com.termux/files/home/Stockfish_nodchip/src'
make: *** [Makefile:775: profile-build] Error 2
How to resolve this problem?
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 6 Days, 14 Hours, 20 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 »

Edit: the project works perfectly, I just had to select the main folder ("Texel Chess Engine") on Open and not the "texelChessEngine" subfolder. I managed to product with Build -> Generate APK a working APK containing a working Texel Engine tested on Droidfish.

Now there is only one problem left: the most of the top engines nowadays are written in C++ (such as Stockfish); I didn't see a single .cpp file inside the "Texel Chess Engine" folder. I have a "StockfishChessEngine" project downloaded somewhere but there too I don't see a single C++ file...
Archimedes wrote: 07/02/2023, 11:31 I don't know what the problem is. Explain step by step what you are actually doing.

If I load the project into Android Studio (takes a little time the first time), don't change anything and then immediately create a signed APK file (Build --> Generate Signed Bundle / APK... --> APK), I don't get an error message. I get an installer for the Texel Chess Engine.
Archimedes

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

Re: Compiling for Android

Post by Archimedes »

kramnik wrote: 07/02/2023, 23:15 Now there is only one problem left: the most of the top engines nowadays are written in C++ (such as Stockfish); I didn't see a single .cpp file inside the "Texel Chess Engine" folder. I have a "StockfishChessEngine" project downloaded somewhere but there too I don't see a single C++ file...
Read the short documentation I wrote. You don't need source files, but the ready compiled native chess engines. Just copy the chess engines in the appropriate directories (e.g. "texelChessEngine\src\main\jniLibs").
kramnik

Top contribute Forum
Forum Contributions
Points: 40 305,00 
Posts: 1924
Joined: 04/11/2019, 14:45
Status: Offline (Active 3 Months, 6 Days, 14 Hours, 20 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 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:

Image


And the Stockfish project found here https://github.com/gkalab/chessenginesupport-androidlib gives errors:

https://i.ibb.co/4F21w7T/Stockfish-project-giving-errors-on-Android-Studio.jpg
Archimedes wrote: 08/02/2023, 6:53
kramnik wrote: 07/02/2023, 23:15 Now there is only one problem left: the most of the top engines nowadays are written in C++ (such as Stockfish); I didn't see a single .cpp file inside the "Texel Chess Engine" folder. I have a "StockfishChessEngine" project downloaded somewhere but there too I don't see a single C++ file...
Read the short documentation I wrote. You don't need source files, but the ready compiled native chess engines. Just copy the chess engines in the appropriate directories (e.g. "texelChessEngine\src\main\jniLibs").
Archimedes

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

Re: Compiling for Android

Post by Archimedes »

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: Online (Active 2 Hours, 3 Minutes ago)
Medals: 2
Topics: 158
Reputation: 7111
Been thanked: 6477 times

Re: Compiling for Android

Post by Archimedes »

And please remember, the name of the executable file should always start with "lib" and end with the extension ".so". If the executable is called stockfish_polyglot_15_1, you must rename it as follows:

Code: Select all

libstockfish_polyglot_15_1.so
Post Reply

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