Skip to content

Build for Android failing: error: no template named 'unordered_map' in namespace 'std' #1291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Danmoreng opened this issue Mar 2, 2025 · 6 comments

Comments

@Danmoreng
Copy link

Danmoreng commented Mar 2, 2025

Describe the bug
When building onnxruntime-genai for Android on Windows using OpenJDK 21, NDK 25.2, and CMake 3.31.6, the build fails with errors error: no template named 'unordered_map' in namespace 'std'; did you mean 'nlohmann::ordered_map'?
I also tried to build the project under Linux with JDK 17 and NDK 25.2 and got the same errors.

ChatGPT problem idea:

The error message suggests a potential conflict with nlohmann::ordered_map. This issue appears to be caused by missing includes in the generated onnxruntime-extensions source files (for example, in tokenizer_common.h and c_api_utils.hpp).

To Reproduce
Steps to reproduce the behavior:

  1. Clone the onnxruntime-genai repository.
  2. Try to build the project:
    python build.py --build_java --android --android_home "[...]\AppData\Local\Android\Sdk" --android_ndk_path "[...]\AppData\Local\Android\Sdk\ndk\25.2.9519653" --android_abi arm64-v8a --config Release
    
  3. The build fails with errors:
    error: no template named 'unordered_map' in namespace 'std'
    

Expected behavior
The build should complete successfully. The project should include the proper headers (e.g., <unordered_map>) so that std::unordered_map is correctly recognized by the compiler.

Desktop:

  • OS: Windows 11
  • Compiler: Clang (Android NDK 25.2)
  • CMake: 3.31.6

Relevant Log

-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: [...]/AppData/Local/Android/Sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using ONNX Runtime package Microsoft.ML.OnnxRuntime version 1.20.0-dev-20241007-1101-407c1ab2e2
-- ORT_HEADER_DIR: [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/ortlib-src/build/native/include
-- ORT_LIB_DIR: [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/ortlib-src/runtimes/android/native/jni/arm64-v8a
Loading Dependencies URLs ...
Loading Dependencies ...
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD

[...]

[131/208] Building C object _deps/onnxruntime_extensions-build/CMakeFiles/libpng_static_c.dir/__/dlib-src/dlib/external/zlib/inflate.c.o
warning: unknown warning option '-Wno-deprecated-non-prototype'; did you mean '-Wno-deprecated-coroutine'? [-Wunknown-warning-option]
1 warning generated.
[158/208] Building CXX object _deps/onnxruntime_extensions-build/CMakeFiles/ocos_operators.dir/operators/tokenizer/bpe_kernels.cc.o
FAILED: _deps/onnxruntime_extensions-build/CMakeFiles/ocos_operators.dir/operators/tokenizer/bpe_kernels.cc.o
[...]\AppData\Local\Android\Sdk\ndk\25.2.9519653\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android27 --sysroot=[...]/AppData/Local/Android/Sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/windows-x86_64/sysroot -DENABLE_C_API -DENABLE_DLIB -DENABLE_DR_LIBS -DENABLE_GPT2_TOKENIZER -DENABLE_MATH -DENABLE_TOKENIZER -DENABLE_VISION -DJSON_HAS_CPP_17=1 -DOCOS_ENABLE_VENDOR_IMAGE_CODECS -DOCOS_SHARED_LIBRARY -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/ortlib-src/build/native/include -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/gsl-src/include -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/include -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/include/custom_op -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/base -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/dlib-src -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/dlib-src/dlib/external/libpng -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/dlib-src/dlib/external/libjpeg -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/nlohmann_json-src/include -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/dlib-src/dlib/external/zlib -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/dr_libs-src -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -O3 -DNDEBUG  -std=c++17 -fPIC -MD -MT _deps/onnxruntime_extensions-build/CMakeFiles/ocos_operators.dir/operators/tokenizer/bpe_kernels.cc.o -MF _deps\onnxruntime_extensions-build\CMakeFiles\ocos_operators.dir\operators\tokenizer\bpe_kernels.cc.o.d -o _deps/onnxruntime_extensions-build/CMakeFiles/ocos_operators.dir/operators/tokenizer/bpe_kernels.cc.o -c [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.cc
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.cc:9:
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.h:11:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizer_common.h:38:23: error: no template named 'unordered_map' in namespace 'std'; did you mean 'nlohmann::ordered_map'?
using AddedTokenMap = std::unordered_map<std::u32string, AddedToken>;
                      ^~~~~~~~~~~~~~~~~~
                      nlohmann::ordered_map
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/nlohmann_json-src/include/nlohmann/json_fwd.hpp:67:8: note: 'nlohmann::ordered_map' declared here
struct ordered_map;
       ^
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.cc:9:
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.h:11:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizer_common.h:38:28: error: too few template arguments for class template 'ordered_map'
using AddedTokenMap = std::unordered_map<std::u32string, AddedToken>;
                           ^
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/nlohmann_json-src/include/nlohmann/json_fwd.hpp:67:8: note: template is declared here
struct ordered_map;
       ^
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.cc:9:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.h:28:41: error: no type named 'AddedTokenMap' in namespace 'ort_extensions'; did you mean 'AddedToken'?
  using AddedTokenMap = ort_extensions::AddedTokenMap;
                        ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
                                        AddedToken
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizer_common.h:20:8: note: 'AddedToken' declared here
struct AddedToken final {
       ^
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.cc:10:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizer_jsconfig.hpp:248:3: error: unknown type name 'AddedTokenMap'; did you mean 'CLIPTokenizer::AddedTokenMap'?
  AddedTokenMap added_tokens_;
  ^~~~~~~~~~~~~
  CLIPTokenizer::AddedTokenMap
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.h:28:9: note: 'CLIPTokenizer::AddedTokenMap' declared here
  using AddedTokenMap = ort_extensions::AddedTokenMap;
        ^
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.cc:10:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizer_jsconfig.hpp:284:23: error: no member named 'emplace' in 'ort_extensions::AddedToken'
        added_tokens_.emplace(ustring(tok_extended.content_), tok_extended);
        ~~~~~~~~~~~~~ ^
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.cc:11:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_tokenizer_model.hpp:313:30: error: unknown type name 'AddedTokenMap'; did you mean 'CLIPTokenizer::AddedTokenMap'?
  void LoadAddedTokens(const AddedTokenMap& added_tokens) {
                             ^~~~~~~~~~~~~
                             CLIPTokenizer::AddedTokenMap
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.h:28:9: note: 'CLIPTokenizer::AddedTokenMap' declared here
  using AddedTokenMap = ort_extensions::AddedTokenMap;
        ^
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.cc:11:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_tokenizer_model.hpp:323:70: error: unknown type name 'AddedTokenMap'; did you mean 'CLIPTokenizer::AddedTokenMap'?
  bpe::TokenPairs SplitByAddedAndSpecial(const ustring& input, const AddedTokenMap& t_map) const {
                                                                     ^~~~~~~~~~~~~
                                                                     CLIPTokenizer::AddedTokenMap
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.h:28:9: note: 'CLIPTokenizer::AddedTokenMap' declared here
  using AddedTokenMap = ort_extensions::AddedTokenMap;
        ^
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.cc:11:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_tokenizer_model.hpp:314:35: error: invalid range expression of type 'const CLIPTokenizer::AddedTokenMap' (aka 'const ort_extensions::AddedToken'); no viable 'begin' function available
    for (const auto& [key, token] : added_tokens) {
                                  ^ ~~~~~~~~~~~~
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_tokenizer_model.hpp:337:40: error: no member named 'find' in 'ort_extensions::AddedToken'
          auto iter_tok_extend = t_map.find(std::u32string(token));
                                 ~~~~~ ^
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_tokenizer_model.hpp:338:40: error: no member named 'end' in 'ort_extensions::AddedToken'
          if (iter_tok_extend != t_map.end()) {
                                 ~~~~~ ^
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.cc:681:21: error: no member named 'emplace' in 'ort_extensions::AddedToken'
      added_tokens_.emplace(ustring(tok_extended.content_), tok_extended);
      ~~~~~~~~~~~~~ ^
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.cc:693:43: error: no member named 'find' in 'ort_extensions::AddedToken'
      auto existing_token = added_tokens_.find(ustring(token.value("content", "")));
                            ~~~~~~~~~~~~~ ^
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.cc:694:43: error: no member named 'end' in 'ort_extensions::AddedToken'
      if (existing_token == added_tokens_.end()) {  // Token doesn't exist yet
                            ~~~~~~~~~~~~~ ^
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.cc:706:23: error: no member named 'emplace' in 'ort_extensions::AddedToken'
        added_tokens_.emplace(ustring(added_token.content_), added_token);
        ~~~~~~~~~~~~~ ^
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.cc:712:39: error: invalid range expression of type 'KernelBpeTokenizer::AddedTokenMap' (aka 'ort_extensions::AddedToken'); no viable 'begin' function available
  for (const auto& [key, added_token] : added_tokens_) {
                                      ^ ~~~~~~~~~~~~~
15 errors generated.
[167/208] Building CXX object _deps/onnxruntime_extensions-build/CMakeFiles/ocos_operators.dir/operators/tokenizer/tokenizers.cc.o
FAILED: _deps/onnxruntime_extensions-build/CMakeFiles/ocos_operators.dir/operators/tokenizer/tokenizers.cc.o
[...]\AppData\Local\Android\Sdk\ndk\25.2.9519653\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android27 --sysroot=[...]/AppData/Local/Android/Sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/windows-x86_64/sysroot -DENABLE_C_API -DENABLE_DLIB -DENABLE_DR_LIBS -DENABLE_GPT2_TOKENIZER -DENABLE_MATH -DENABLE_TOKENIZER -DENABLE_VISION -DJSON_HAS_CPP_17=1 -DOCOS_ENABLE_VENDOR_IMAGE_CODECS -DOCOS_SHARED_LIBRARY -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/ortlib-src/build/native/include -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/gsl-src/include -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/include -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/include/custom_op -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/base -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/dlib-src -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/dlib-src/dlib/external/libpng -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/dlib-src/dlib/external/libjpeg -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/nlohmann_json-src/include -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/dlib-src/dlib/external/zlib -I[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/dr_libs-src -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -O3 -DNDEBUG  -std=c++17 -fPIC -MD -MT _deps/onnxruntime_extensions-build/CMakeFiles/ocos_operators.dir/operators/tokenizer/tokenizers.cc.o -MF _deps\onnxruntime_extensions-build\CMakeFiles\ocos_operators.dir\operators\tokenizer\tokenizers.cc.o.d -o _deps/onnxruntime_extensions-build/CMakeFiles/ocos_operators.dir/operators/tokenizer/tokenizers.cc.o -c [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizers.cc
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizers.cc:7:
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.h:11:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizer_common.h:38:23: error: no template named 'unordered_map' in namespace 'std'; did you mean 'nlohmann::ordered_map'?
using AddedTokenMap = std::unordered_map<std::u32string, AddedToken>;
                      ^~~~~~~~~~~~~~~~~~
                      nlohmann::ordered_map
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/nlohmann_json-src/include/nlohmann/json_fwd.hpp:67:8: note: 'nlohmann::ordered_map' declared here
struct ordered_map;
       ^
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizers.cc:7:
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.h:11:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizer_common.h:38:28: error: too few template arguments for class template 'ordered_map'
using AddedTokenMap = std::unordered_map<std::u32string, AddedToken>;
                           ^
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/nlohmann_json-src/include/nlohmann/json_fwd.hpp:67:8: note: template is declared here
struct ordered_map;
       ^
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizers.cc:7:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.h:28:41: error: no type named 'AddedTokenMap' in namespace 'ort_extensions'; did you mean 'AddedToken'?
  using AddedTokenMap = ort_extensions::AddedTokenMap;
                        ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
                                        AddedToken
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizer_common.h:20:8: note: 'AddedToken' declared here
struct AddedToken final {
       ^
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizers.cc:8:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_tokenizer_model.hpp:313:30: error: unknown type name 'AddedTokenMap'; did you mean 'CLIPTokenizer::AddedTokenMap'?
  void LoadAddedTokens(const AddedTokenMap& added_tokens) {
                             ^~~~~~~~~~~~~
                             CLIPTokenizer::AddedTokenMap
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.h:28:9: note: 'CLIPTokenizer::AddedTokenMap' declared here
  using AddedTokenMap = ort_extensions::AddedTokenMap;
        ^
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizers.cc:8:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_tokenizer_model.hpp:323:70: error: unknown type name 'AddedTokenMap'; did you mean 'CLIPTokenizer::AddedTokenMap'?
  bpe::TokenPairs SplitByAddedAndSpecial(const ustring& input, const AddedTokenMap& t_map) const {
                                                                     ^~~~~~~~~~~~~
                                                                     CLIPTokenizer::AddedTokenMap
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.h:28:9: note: 'CLIPTokenizer::AddedTokenMap' declared here
  using AddedTokenMap = ort_extensions::AddedTokenMap;
        ^
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizers.cc:8:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_tokenizer_model.hpp:314:35: error: invalid range expression of type 'const CLIPTokenizer::AddedTokenMap' (aka 'const ort_extensions::AddedToken'); no viable 'begin' function available
    for (const auto& [key, token] : added_tokens) {
                                  ^ ~~~~~~~~~~~~
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_tokenizer_model.hpp:337:40: error: no member named 'find' in 'ort_extensions::AddedToken'
          auto iter_tok_extend = t_map.find(std::u32string(token));
                                 ~~~~~ ^
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_tokenizer_model.hpp:338:40: error: no member named 'end' in 'ort_extensions::AddedToken'
          if (iter_tok_extend != t_map.end()) {
                                 ~~~~~ ^
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizers.cc:10:
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizer_op_impl.hpp:7:
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/ugm_kernels.hpp:24:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizer_jsconfig.hpp:248:3: error: unknown type name 'AddedTokenMap'; did you mean 'CLIPTokenizer::AddedTokenMap'?
  AddedTokenMap added_tokens_;
  ^~~~~~~~~~~~~
  CLIPTokenizer::AddedTokenMap
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/bpe_kernels.h:28:9: note: 'CLIPTokenizer::AddedTokenMap' declared here
  using AddedTokenMap = ort_extensions::AddedTokenMap;
        ^
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizers.cc:10:
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizer_op_impl.hpp:7:
In file included from [...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/ugm_kernels.hpp:24:
[...]/StudioProjects/onnxruntime-genai/build/Android/Release/_deps/onnxruntime_extensions-src/operators/tokenizer/tokenizer_jsconfig.hpp:284:23: error: no member named 'emplace' in 'ort_extensions::AddedToken'
        added_tokens_.emplace(ustring(tok_extended.content_), tok_extended);
        ~~~~~~~~~~~~~ ^
10 errors generated.
[171/208] Building CXX object _deps/onnxruntime_extensions-build/CMakeFiles/ocos_operators.dir/operators/math/math.cc.o
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "[...]\StudioProjects\onnxruntime-genai\build.py", line 662, in <module>
    build(arguments, environment)
  File "[...]\StudioProjects\onnxruntime-genai\build.py", line 587, in build
    util.run(make_command, env=env)
  File "[...]\StudioProjects\onnxruntime-genai\tools\python\util\run.py", line 56, in run
    completed_process = subprocess.run(
  File "[...]\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['C:\\Program Files\\CMake\\bin\\cmake.EXE', '--build', '[...]\\StudioProjects\\onnxruntime-genai\\build\\Android\\Release', '--config', 'Release']' returned non-zero exit status 1.
@RyanUnderhill
Copy link
Contributor

This looks like the bug is actually in the https://github.com/microsoft/onnxruntime-extensions project, can you please log the issue there?

@baijumeswani
Copy link
Collaborator

@Danmoreng you can use the prebuilt aar file in case you want to avoid building from source: https://github.com/microsoft/onnxruntime-genai/releases/tag/v0.6.0

@baijumeswani
Copy link
Collaborator

This is the build command we use to build the android aar:

python3 tools/ci_build/github/android/build_aar_package.py --config Release tools/ci_build/github/android/default_aar_build_settings.json

We use ndk 26.3.11579264 to build. You might need to set the necessary env variables

@Danmoreng
Copy link
Author

@baijumeswani Thanks! I want to try getting phi4 to work on Android, that’s why I cannot use the prebuilt aar file which is 3 weeks old. I followed the documentation over here https://onnxruntime.ai/docs/genai/howto/build-from-source.html
I will tryout the command you provided when I get the time.

@baijumeswani
Copy link
Collaborator

0.6.0 should work for phi4. It won't work for phi4-multimodal. But it should work for phi-4 text models.

@Danmoreng
Copy link
Author

Thanks @baijumeswani, with the pre-built 0.6.0 I got phi4-instruct text working. However, I am specifically interested in the multi modal version. I had no luck with your command for building it either, but got a different error. I will try further this weekend.
Command I tried with:

python tools/ci_build/github/android/build_aar_package.py --android_home "C:\Users\sebas\AppData\Local\Android\Sdk" --android_ndk_path "C:\Users\sebas\AppData\Local\Android\Sdk\ndk\26.3.11579264" --config Release tools/ci_build/github/android/default_aar_build_settings.json

Error

> Task :app:mergeExtDexDebug
ERROR:C:\Users\sebas\.gradle\caches\transforms-4\a0f10d7b56c8912cac15fe1a6ba19032\transformed\jetified-onnxruntime-genai-runtime.jar: D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null

> Task :app:mergeExtDexDebug FAILED
> Task :app:processDebugManifestForPackage

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeExtDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform onnxruntime-genai-.aar (:onnxruntime-genai:) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.status=integration, org.gradle.usage=java-runtime}.
      > Execution failed for DexingWithClasspathTransform: C:\Users\sebas\.gradle\caches\transforms-4\a0f10d7b56c8912cac15fe1a6ba19032\transformed\jetified-onnxruntime-genai-runtime.jar.
         > Error while dexing.

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:mergeExtDexDebug'.
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:38)
 
[...]
Caused by: org.gradle.api.internal.artifacts.transform.TransformException: Execution failed for DexingWithClasspathTransform: C:\Users\sebas\.gradle\caches\transforms-4\a0f10d7b56c8912cac15fe1a6ba19032\transformed\jetified-onnxruntime-genai-runtime.jar.
[...]

Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.

[...]
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: C:\Users\sebas\.gradle\caches\transforms-4\a0f10d7b56c8912cac15fe1a6ba19032\transformed\jetified-onnxruntime-genai-runtime.jar:ai/onnxruntime/genai/Generator$Iterator.class

[...]
Caused by: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null

[...]
Caused by: [CIRCULAR REFERENCE: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants