Building TFLite fails on nnapi_delegate requiring C++20 extensions 
I'm also having this issue Hi @kubaraczkowski, can you please share your model.tflite file used in this step of reproducing:

```sh
bash tensorflow/lite/tools/build_aar.sh \
  --input_models=model.tflite \
  --target_archs=arm64-v8a
```

Thanks! Hi @pkgoogle ! 

The TF model that I am using that also produces the same error is located here:

https://github.com/naedx/tflite_android_build/blob/dev/models/whisper.tflite 




### Setup/config details:

<details>

```bash

tf-docker /host_dir > ./tensorflow_src/configure
You have bazel 7.1.1 installed.
Please specify the location of python. [Default is /usr/bin/python3]: 


Found possible Python library paths:
  /usr/lib/python3/dist-packages
  /usr/local/lib/python3.11/dist-packages
Please input the desired Python library path to use.  Default is [/usr/lib/python3/dist-packages]

Do you wish to build TensorFlow with ROCm support? [y/N]: 
No ROCm support will be enabled for TensorFlow.

Do you wish to build TensorFlow with CUDA support? [y/N]: 
No CUDA support will be enabled for TensorFlow.

Do you want to use Clang to build TensorFlow? [Y/n]: 
Clang will be used to compile TensorFlow.

Please specify the path to clang executable. [Default is /usr/lib/llvm-17/bin/clang]: 


You have Clang 17.0.6 installed.

Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -Wno-sign-compare]: 


Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: y
Searching for NDK and SDK installations.

Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details.
	--config=mkl         	# Build with MKL support.
	--config=mkl_aarch64 	# Build with oneDNN and Compute Library for the Arm Architecture (ACL).
	--config=monolithic  	# Config for mostly static monolithic build.
	--config=numa        	# Build with NUMA support.
	--config=dynamic_kernels	# (Experimental) Build kernels into separate shared objects.
	--config=v1          	# Build with TensorFlow 1 API instead of TF 2 API.
Preconfigured Bazel build configs to DISABLE default on features:
	--config=nogcp       	# Disable GCP support.
	--config=nonccl      	# Disable NVIDIA NCCL support.
Configuration finished

```

</details>



### Build:

```bash

tf-docker /host_dir > tensorflow_src/tensorflow/lite/tools/build_aar.sh \
  --input_models=/host_dir/models/whisper.tflite \
  --target_archs=arm64-v8a

```

<details>

```bash

+++ dirname tensorflow_src/tensorflow/lite/tools/build_aar.sh
++ cd tensorflow_src/tensorflow/lite/tools
++ pwd
+ SCRIPT_DIR=/host_dir/tensorflow_src/tensorflow/lite/tools
++ cd /host_dir/tensorflow_src/tensorflow/lite/tools/../../../
++ pwd
+ ROOT_DIR=/host_dir/tensorflow_src
+ TARGET_ARCHS=x86,x86_64,arm64-v8a,armeabi-v7a
+ '[' '!' -z ']'
+ '[' 2 -gt 4 ']'
+ for i in "$@"
+ case $i in
+ FLAG_MODELS=/host_dir/models/whisper.tflite
+ shift
+ for i in "$@"
+ case $i in
+ TARGET_ARCHS=arm64-v8a
+ shift
+ cd /host_dir/tensorflow_src
+ '[' '!' -f /host_dir/tensorflow_src/.tf_configure.bazelrc ']'
+ grep -q ANDROID_SDK_HOME /host_dir/tensorflow_src/.tf_configure.bazelrc
+ '[' -z /host_dir/models/whisper.tflite ']'
+ TMP_DIR=/host_dir/tensorflow_src/tmp/
+ rm -rf /host_dir/tensorflow_src/tmp/
+ mkdir -p /host_dir/tensorflow_src/tmp/
+ MODEL_NAMES=
++ echo /host_dir/models/whisper.tflite
++ sed 's/,/ /g'
+ for model in $(echo ${FLAG_MODELS} | sed "s/,/ /g")
+ cp /host_dir/models/whisper.tflite /host_dir/tensorflow_src/tmp/
++ basename /host_dir/models/whisper.tflite
+ MODEL_NAMES=,whisper.tflite
+ TFLITE_OPS_SRCS=
++ echo
++ sed 's/,/ /g'
+ generate_tflite_aar
+ pushd /host_dir/tensorflow_src/tmp/
+ message=('load("//tensorflow/lite:build_def.bzl", "tflite_custom_android_library")' 'load("//tensorflow/lite/java:aar_with_jni.bzl", "aar_with_jni")' '' 'tflite_custom_android_library(' '    name = "custom_tensorflowlite",')
+ message+=('    '$(generate_list_field "models" $MODEL_NAMES))
++ generate_list_field models ,whisper.tflite
++ local name=models
++ local list_string=,whisper.tflite
++ list=(${list_string//,/ })
++ local list
++ message=("$name=[")
++ local message
++ for item in "${list[@]}"
++ message+=("\"$item\",")
++ message+=('],')
++ printf %s 'models=[' '"whisper.tflite",' '],'
+ message+=('    '$(generate_list_field "srcs" $TFLITE_OPS_SRCS))
++ generate_list_field srcs
++ local name=srcs
++ local list_string=
++ list=(${list_string//,/ })
++ local list
++ message=("$name=[")
++ local message
++ message+=('],')
++ printf %s 'srcs=[' '],'
+ message+=('    '$(generate_list_field "deps" $FLAG_TFLITE_OPS_DEPS))
++ generate_list_field deps
++ local name=deps
++ local list_string=
++ list=(${list_string//,/ })
++ local list
++ message=("$name=[")
++ local message
++ message+=('],')
++ printf %s 'deps=[' '],'
+ message+=(')' '' 'aar_with_jni(' '    name = "tensorflow-lite",' '    android_library = ":custom_tensorflowlite",' ')' '')
+ printf '%s\n' 'load("//tensorflow/lite:build_def.bzl", "tflite_custom_android_library")' 'load("//tensorflow/lite/java:aar_with_jni.bzl", "aar_with_jni")' '' 'tflite_custom_android_library(' '    name = "custom_tensorflowlite",' '    models=["whisper.tflite",],' '    srcs=[],' '    deps=[],' ')' '' 'aar_with_jni(' '    name = "tensorflow-lite",' '    android_library = ":custom_tensorflowlite",' ')' ''
+ popd
+ bazel build -c opt --config=opt --cxxopt=--std=c++17 --fat_apk_cpu=arm64-v8a --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder --host_crosstool_top=@bazel_tools//tools/cpp:toolchain //tmp:tensorflow-lite
INFO: Reading 'startup' options from /host_dir/tensorflow_src/.bazelrc: --windows_enable_symlinks
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=265
INFO: Reading rc options for 'build' from /host_dir/tensorflow_src/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'build' from /etc/bazel.bazelrc:
  'build' options: --action_env=DOCKER_CACHEBUSTER=1712448870699421512 --host_action_env=DOCKER_HOST_CACHEBUSTER=1712448870763599131
INFO: Reading rc options for 'build' from /host_dir/tensorflow_src/.bazelrc:
  'build' options: --define framework_shared_object=true --define tsl_protobuf_header_only=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --features=-force_no_whole_archive --enable_platform_specific_config --define=with_xla_support=true --config=short_logs --config=v2 --define=no_aws_support=true --define=no_hdfs_support=true --experimental_cc_shared_library --experimental_link_static_libraries_once=false --incompatible_enforce_config_setting_visibility
INFO: Reading rc options for 'build' from /host_dir/tensorflow_src/.tf_configure.bazelrc:
  'build' options: --action_env PYTHON_BIN_PATH=/usr/bin/python3 --action_env PYTHON_LIB_PATH=/usr/lib/python3/dist-packages --python_path=/usr/bin/python3 --action_env CLANG_COMPILER_PATH=/usr/lib/llvm-17/bin/clang --repo_env=CC=/usr/lib/llvm-17/bin/clang --repo_env=BAZEL_COMPILER=/usr/lib/llvm-17/bin/clang --copt=-Wno-gnu-offsetof-extensions --action_env ANDROID_NDK_HOME=/android/ndk --action_env ANDROID_NDK_VERSION=25 --action_env ANDROID_NDK_API_LEVEL=30 --action_env ANDROID_BUILD_TOOLS_VERSION=34.0.0 --action_env ANDROID_SDK_API_LEVEL=30 --action_env ANDROID_SDK_HOME=/android/sdk
INFO: Found applicable config definition build:short_logs in file /host_dir/tensorflow_src/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:v2 in file /host_dir/tensorflow_src/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition build:opt in file /host_dir/tensorflow_src/.tf_configure.bazelrc: --copt=-Wno-sign-compare --host_copt=-Wno-sign-compare
INFO: Found applicable config definition build:linux in file /host_dir/tensorflow_src/.bazelrc: --host_copt=-w --copt=-Wno-all --copt=-Wno-extra --copt=-Wno-deprecated --copt=-Wno-deprecated-declarations --copt=-Wno-ignored-attributes --copt=-Wno-array-bounds --copt=-Wunused-result --copt=-Werror=unused-result --copt=-Wswitch --copt=-Werror=switch --copt=-Wno-error=unused-but-set-variable --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --config=dynamic_kernels --experimental_guard_against_concurrent_changes
INFO: Found applicable config definition build:dynamic_kernels in file /host_dir/tensorflow_src/.bazelrc: --define=dynamic_loaded_kernels=true --copt=-DAUTOLOAD_DYNAMIC_KERNELS
INFO: Build option --define has changed, discarding analysis cache.
INFO: Analyzed target //tmp:tensorflow-lite (1 packages loaded, 12614 targets configured).
INFO: Found 1 target...
ERROR: /host_dir/tensorflow_src/tensorflow/lite/delegates/nnapi/BUILD:14:11: Compiling tensorflow/lite/delegates/nnapi/nnapi_delegate.cc failed: (Exit 1): clang failed: error executing command (from target //tensorflow/lite/delegates/nnapi:nnapi_delegate_no_nnapi_implementation) external/androidndk/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -no-canonical-prefixes '--target=aarch64-linux-android30' -fdiagnostics-color -Wa,--noexecstack -fno-exceptions '-std=gnu++17' ... (remaining 158 arguments skipped)
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:522:7: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
      .type = nn_type,
      ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:1529:45: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
    ANeuralNetworksOperandType operand_type{.type = nn_type};
                                            ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:1682:45: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
    ANeuralNetworksOperandType operand_type{.type = nn_type};
                                            ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:1701:45: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
    ANeuralNetworksOperandType operand_type{.type = nn_type,
                                            ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:1743:9: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
        .type = nn_type,
        ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:1844:17: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
                .channelDim = static_cast<uint32_t>(
                ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:6915:7: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
      .init = [](TfLiteContext* context, const char* buffer,
      ^


```

</details>

```bash

7 errors generated.
Target //tmp:tensorflow-lite failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 11.868s, Critical Path: 8.84s
INFO: 42 processes: 11 internal, 31 local.
FAILED: Build did NOT complete successfully

```

The same errors are produced even without specifying a model `tensorflow_src/tensorflow/lite/tools/build_aar.sh  --target_archs=arm64-v8a` I was able to reproduce with the original steps and the uploaded whisper model.

Hi @terryheo, can you please take a look? Thanks. Hey @terryheo, any progress on this? Hi @terryheo, this is still breaking the builds - did you have any chance to look at this?
### Issue type

Build/Install

### Have you reproduced the bug with TensorFlow Nightly?

No

### Source

source

### TensorFlow version

2.16.1

### Custom code

No

### OS platform and distribution

Docker

### Mobile device

_No response_

### Python version

3.11

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

Hi,

I'm following the steps to build TF Lite using docker (https://www.tensorflow.org/lite/android/lite_build#set_up_build_environment_using_docker) with TF release 2.16.1 (also tried 2.15). No modifications to the sources, Dockerfile or commands, only change is limiting the target architectures to arm64_v8a

The step of building aar for a given model fails by throwing C++20 extensions needed by the nnapi delegate. It seems that the rest of tooling is using gnu++17?




### Standalone code to reproduce the issue

```shell
docker build . -t tflite-builder -f tflite-android.Dockerfile
docker run -it -v $PWD:/host_dir tflite-builder bash

sdkmanager \
  "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
  "platform-tools" \
  "platforms;android-${ANDROID_API_LEVEL}"

./configure

bazel build -c opt --cxxopt=--std=c++17 --config=android_arm64 \
  --fat_apk_cpu=arm64-v8a \
  --define=android_dexmerger_tool=d8_dexmerger \
  --define=android_incremental_dexing_tool=d8_dexbuilder \
  //tensorflow/lite/java:tensorflow-lite


bash tensorflow/lite/tools/build_aar.sh \
  --input_models=model.tflite \
  --target_archs=arm64-v8a
```


### Relevant log output

```shell
ERROR: /host_dir/tensorflow-2.16.1/tensorflow/lite/delegates/nnapi/BUILD:14:11: Compiling tensorflow/lite/delegates/nnapi/nnapi_delegate.cc failed: (Exit 1): clang failed: error executing command (from target //tensorflow/lite/delegates/nnapi:nnapi_delegate_no_nnapi_implementation) external/androidndk/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -no-canonical-prefixes '--target=aarch64-linux-android30' -fdiagnostics-color -Wa,--noexecstack -fno-exceptions '-std=gnu++17' ... (remaining 158 arguments skipped)
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:522:7: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
      .type = nn_type,
      ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:1529:45: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
    ANeuralNetworksOperandType operand_type{.type = nn_type};
                                            ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:1682:45: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
    ANeuralNetworksOperandType operand_type{.type = nn_type};
                                            ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:1701:45: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
    ANeuralNetworksOperandType operand_type{.type = nn_type,
                                            ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:1743:9: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
        .type = nn_type,
        ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:1844:17: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
                .channelDim = static_cast<uint32_t>(
                ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:6915:7: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
      .init = [](TfLiteContext* context, const char* buffer,
      ^
7 errors generated.
Target //tmp:tensorflow-lite failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 11.395s, Critical Path: 8.54s
INFO: 62 processes: 21 internal, 41 local.
FAILED: Build did NOT complete successfully
```
