C++20 std::stop_token not building for andorid

Hi Team,

I’m trying to build our game including std::stop_token for Android, but I get the next build error:

error: no type named 'stop_token' in namespace 'std'
  68 |   std::stop_token stopToken;
   |   ~~~~~^




Source code:

#include <stop_token>

std::stop_token stopToken;

Our Unreal plugin have the C++20 features enabled in the build.cs:

CppStandard = CppStandardVersion.Cpp20;

And the same code builds properly for windows.

How could I fix this build error?

Android SDK Version: 34.0.0

Android NDK Version: 27.2.12479018

[Attachment Removed]

Hi Xavier,

This issue isn’t UE related and is a limitation of NDK 27/28 in which std::stop_token is still experimental and not exposed by default:

  • in $NDKROOT/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/__stop_token/stop_token.h, the declaration of stop_token is wrapped in !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN)
  • in $NDKROOT/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/__config , _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN is defined unless _LIBCPP_ENABLE_EXPERIMENTAL is defined.

As a workaround, and at your own risk, you can force enable these in one of two ways:

In your app’s Target.cs add:

	if (Target.Platform == UnrealTargetPlatform.Android)
        {
            GlobalDefinitions.Add("_LIBCPP_ENABLE_EXPERIMENTAL");
        }

Or at the source level, include <stop_token> as follows:

#undef _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN
#include <stop_token>

Alternatively, moving to NDK 29 would be required where stop_token is no longer wrapped in #if !defined _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN and is available by default.

Best regards.

[Attachment Removed]

Great, was working for me.

Thanks!

[Attachment Removed]