Fail to make an android build

I use those step to build android, but failed.

my system is ubuntu 22.04

  1. clone vcmi code and prepair build environment:
  2. download conna deps aarch64-v8a.txz and extract to ~/.conan
  3. type comman below

cd vcmi
conan install . --install-folder=./conan-generated --no-imports --build=never --profile:build=default --profile:host=CI/conan/android-64 -c tools.android:ndk_path=~/Android/Sdk/ndk/25.2.9519653
cmake -S . -B …/build -G Ninja -D CMAKE_BUILD_TYPE=Release -D ENABLE_CCACHE:BOOL=ON --toolchain conan-generated/conan_toolchain.cmake
cmake --build …/build

my buid failed with error:

FAILED: AI/FuzzyLite/fuzzylite/CMakeFiles/fl-obj.dir/src/main.cpp.o
ccache /home/demonking/Android/Sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --sysroot=/home/demonking/Android/Sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/linux-x86_64/sysroot -DENABLE_SINGLE_APP_BUILD -DFL_BUILD_PATH="/home/demonking/vcmi" -DUSE_SYSTEM_MINIZIP -DVCMI_VERSION_MAJOR=1 -DVCMI_VERSION_MINOR=5 -DVCMI_VERSION_PATCH=0 -DVCMI_VERSION_STRING=“1.5.0” -I/home/demonking/vcmi/AI/FuzzyLite/fuzzylite/. -pedantic -Wall -Wextra -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -Wall -Wextra -Wpointer-arith -Wuninitialized -Wmismatched-tags -Wno-unused-parameter -Wno-switch -Wno-reorder -Wno-sign-compare -Wno-varargs -Wno-non-literal-null-conversion -Wno-varargs -O3 -DNDEBUG -fPIC -std=c++11 -fPIC -fcolor-diagnostics -Wno-error=deprecated-declarations -std=gnu++17 -MD -MT AI/FuzzyLite/fuzzylite/CMakeFiles/fl-obj.dir/src/main.cpp.o -MF AI/FuzzyLite/fuzzylite/CMakeFiles/fl-obj.dir/src/main.cpp.o.d -o AI/FuzzyLite/fuzzylite/CMakeFiles/fl-obj.dir/src/main.cpp.o -c /home/demonking/vcmi/AI/FuzzyLite/fuzzylite/src/main.cpp
/home/demonking/vcmi/AI/FuzzyLite/fuzzylite/src/main.cpp:24:10: error: no type named ‘set_unexpected’ in namespace ‘std’
std::set_unexpected(fl::Exception::terminate);
~~~~~^
/home/demonking/vcmi/AI/FuzzyLite/fuzzylite/src/main.cpp:24:40: error: definition or redeclaration of ‘terminate’ not allowed inside a function
std::set_unexpected(fl::Exception::terminate);
~~~~~~~~~~~~~~~^
2 errors generated.

both -std=c++11 and -std=gnu++17 are used. gcc seems to treat code as c++11, so compile failed.

how to solve this problem?

the issue seems to come from -std=gnu++17, as std::set_unexpected was removed in C++17. But I wonder what sets it, as our CI (GitHub actions) builds android on ubuntu 22.04 just fine. VCMI does use C++17, but that shouldn’t affect Fuzzylite. Is it possible that you accidentally updated Fuzzylite submodule to the latest version?

I see the following differences:

  1. CI uses CMake presets instead of passing configure flags directly, but I doubt it makes any difference.
  2. CI builds RelWithDebInfo, not Release.

Thank you for reply. This problem waste me a lot of time. and it still not solved.

It seems not the code problem. I replace the .conan with windows precompile package. and compile with preset windows-mingw-conan-linux, It’s OK and I got the windows binary for vcmi. But I use the android precompile package, this error occures.

I use this android dependences: Releases · vcmi/vcmi-dependencies · GitHub

if I specify -s compiler.version=17 or -s compiler.cppstd=17, conan will recompile all the dependencies

Is it the right dependences? And how can I get a detail commands for android compilation?

dependencies are correct, our CI uses them on ubuntu 22.04 without any issues. You can check what CI is doing here: vcmi/.github/workflows/github.yml at develop · vcmi/vcmi · GitHub

all compile commands are in the Ninja file(s) generated by CMake somewhere in the build directory.

is there any specific reason why you want to build for android manually instead of installing nightly build?

I want to develop version witch support joystick for my Odin2 (an Android handheld device). I want to test my new code. So I need to compile a new version.

I am testing my code in Windows with a xbox joystick… It seems work well but I‘m not sure it can be worked in Android.

I will try CI’s commands to make a compilation in Android. But other one who want to do Android compilation maybe failed too, since the document description is too difficult for those one who never use conan before. Add more detail commands may be better?

I mean this document: How to build VCMI (Android) - VCMI Project Wiki

1 Like

well, there’s nothing more easier. Building all the dependencies without Conan is way more difficult.

the latest documentation is here: vcmi/docs/developers/Building_Android.md at develop · vcmi/vcmi · GitHub

a lifehack: submit a draft PR and let CI do the dirty job for you :wink:

I am very gladly to let CI do this job, but I dont know where to get the apk.

And I dont mean not to use conan,I only expect that Andriod build document can show a example like this:

have you read the Conan instructions that are linked to from the “how to build for Android”? They’re very detailed: vcmi/docs/developers/Conan.md at develop · vcmi/vcmi · GitHub

yes,I have read it. This document is very detail for Windows build. I follow it and make a Windows binary successfully. But I cant make an android one since the preset which should be used for Android is not metioned in this document.

Using cmake preset is optional. The “raw” cmake configuration command invocation written in the instructions is the same thing.

Like I said, CI uses different build mode, have you already tried that (passing that build mode or using the same preset that CI uses)? But actually on macos I can build for android in Release mode without any issues.

Have you checked your environment variables? Maybe the forced C++ standard flag is coming from there? Also try checking the cmake cache file, maybe it has some hints.

I first build the windows binary successfully. then l moved ~/.conan and make a new one. put Android dependencies to it. delete the whole vcmi code folder and git clone a new one, but compile failed.

no environment various are changed during this period.

you have compiled successfully. so I think there is something wrong in my building commands. I will check my commands more carefully when I need to compile it.

Deleting source directory isn’t needed.

Are you using the same build folder for windows and android without deleting it by chance? This could be the source of the issue.

FYI Building for windows and android uses completely different compilers and toolchains.

I put the output folder in the source directory as the document does. And I delect the whole source folder and .conan folder. Maybe there are other folder I forget to delete. I plan to create a new vm for Android compilation.

When I finish develop about joystick feature, I will have a try. Thank you for your guidance.

It is still not solved. When I grep c++11 in build folder, there is a lot of lines matched. Which file add it in andriod ?

The issue is in the 17 flag, not in 11

Yes, I make a mistake. I ask for chatgpt , And paste AI/CmakeList.txt to it, it suggest me to add a command:

Set FuzzyLite to use C++11 standard explicitly

set_target_properties(fl-static PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
)

But why 17 flag is still in Fuzzylite?I can not understand

Finally I solved this problem. It is cause by the root CMakeList.txt, set (CMAKE_CXX_STANDARD 17) it enable c++17 globally.

In AI/CMakeList.txt

those code include FuzzyLite into VCMI tree in android, but not include in windows. So windows compilation is OK.

This block not do everything for c++ standard, so FuzzyLite will be added a -std=gnu++17

I use a dirty way to solve it.

Maybe there is a more elegant way to do this. But I am not familiar with CMake. :pensive:

here’s a line from my ninja file on macOS: as you can see, the 11 flag is correctly passed after 17 thus overriding the latter.

build AI/FuzzyLite/fuzzylite/CMakeFiles/fl-obj.dir/src/main.cpp.o: CXX_COMPILER__fl-obj_unscanned_Debug /Users/kambala/dev/vcmi/vcmi/AI/FuzzyLite/fuzzylite/src/main.cpp || cmake_object_order_depends_target_fl-obj
  DEFINES = -DENABLE_LAUNCHER -DENABLE_QT_TRANSLATIONS -DENABLE_SINGLE_APP_BUILD -DFL_BUILD_PATH=\"/Users/kambala/dev/vcmi/vcmi\" -DUSE_SYSTEM_MINIZIP -DVCMI_VERSION_MAJOR=1 -DVCMI_VERSION_MINOR=5 -DVCMI_VERSION_PATCH=0 -DVCMI_VERSION_STRING=\"1.5.0\"
  DEP_FILE = AI/FuzzyLite/fuzzylite/CMakeFiles/fl-obj.dir/src/main.cpp.o.d
  FLAGS = -pedantic -Wall -Wextra -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security   -Wall -Wextra -Wpointer-arith -Wuninitialized -Wmismatched-tags -Wno-unused-parameter -Wno-switch -Wno-reorder -Wno-sign-compare -Wno-varargs -Wno-non-literal-null-conversion -Wno-varargs -fno-limit-debug-info  -fstandalone-debug -std=gnu++17 -fPIC   -std=c++11 -fPIC -fcolor-diagnostics -Wno-error=deprecated-declarations

I’m still sure that it’s an issue with your local environment which you need to investigate on your own.

as a last measure we can enforce 11 standard like you suggest.

btw which cmake and ninja versions are you using?

cmake version 3.22.1
ninja version 1.10.1
This is the lastest version in Ubuntu 22.04.

This problem can be reproduced in this step:

  1. download the lastest ubuntu 22.04 from its official website
  2. create a VMware vm, quick install the OS
  3. apt get all need packages.
  4. canon compile the Android VCMI
1 Like