Not able to build TFLite GPU Delegate dynamic library with bazel for android arm64
Hi @rahul-exp 

Can you please provide the steps you have followed. Did you setup `./configure` for android?

Thanks. @pjpratik Please find the ./configure options I selected for android:
Please specify the location of python: Correct path location provided(Python version 3.9)
Please input the desired Python library path to use: Correct path location provided(Python version 3.9)
Do you wish to build TensorFlow with ROCm support? [y/N]: N
No ROCm support will be enabled for TensorFlow.

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

Do you wish to download a fresh release of clang? (Experimental) [y/N]: N
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -Wno-sign-compare]: Enabled just the default
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: y
Please specify the home path of the Android NDK to use: Provided path for ndk/21.4.7075529
Please specify the (min) Android NDK API level to use: Default of 26
Please specify the home path of the Android SDK to use: Provided sdk path 
Please specify the Android SDK API level to use: 33
Please specify an Android build tools version to use: 34.0.0-rc1
Do you wish to build TensorFlow with iOS support? [y/N]: N
 Other builds for android with below commands are working fine:
1) bazel build -c opt --config=android_arm64 --cpu=arm64-v8a --define tflite_with_xnnpack=true //tensorflow/lite:tensorflowlite
2) bazel build -c opt --config=android_arm64 --cpu=arm64-v8a //tensorflow/lite/delegates/nnapi:nnapi_delegate_no_nnapi_implementation
3)  bazel build -c opt --config=android_arm64 --cpu=arm64-v8a //tensorflow/lite/nnapi:nnapi_implementation Hi @rahul-exp Sorry for the delayed response.

Can you please provide which version of TF you are using?

I couldn't reproduce it at my end and facing different error.

Thanks. TF version on my mac is 2.11.0. I had checked out the latest changes from the main branch of the repo for building the TFLite libraries. Should I switch to a release branch for building TFLite libraries? Hi @rahul-exp Thanks for the information.

I have tried on MacOS (13.2) with Bazel 5.3.0 and using master branch. I was able to succesfully generate `libtensorflowlite_gpu_delegate.so` file. Please find the screenshot below

<img width="806" alt="Screenshot 2023-03-24 at 8 30 13 PM" src="https://user-images.githubusercontent.com/118897289/227563831-edd158dc-ebf7-4e17-ac1a-0dac759e94d7.png">

I have tested on Ubuntu 20.04 with same config and found no issues.

Can you try `bazel clean --expunge` and try the same again.

This is my config for your reference

<img width="811" alt="Screenshot 2023-03-24 at 8 35 04 PM" src="https://user-images.githubusercontent.com/118897289/227564104-7aee04de-ab2b-4eaf-928e-8fb3faaeac58.png">

Thanks.

 This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60012">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60012">No</a>
 @pjpratik I get this error as well, can't build the GPU delegate.
## Setup
1. bazel 5.3.0
1. Fresh clone of tensorflow
1. git checkout v2.13.0
1. run `configure` and use:
```
ANDROID_NDK_HOME="/home/yuval/android/android-ndk-r21e"
ANDROID_NDK_API_LEVEL="21"
ANDROID_BUILD_TOOLS_VERSION="33.0.0"
ANDROID_SDK_API_LEVEL="33"
```
## Build
```sh
$ bazel build -c opt --config=android_arm64 //tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_delegate.so

ERROR: /home/yuval/MyProjects/tensorflow/tensorflow/lite/delegates/gpu/BUILD:225:11: Compiling tensorflow/lite/delegates/gpu/delegate.cc failed: (Exit 1): clang failed: error executing command external/androidndk/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -gcc-toolchain external/androidndk/ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 -target ... (remaining 192 arguments skipped)
tensorflow/lite/delegates/gpu/delegate.cc:786:7: error: use of undeclared identifier 'AHardwareBuffer_acquire'; did you mean 'AHardwareBuffer_Plane'?
      AHardwareBuffer_acquire(ahwb);
      ^
external/androidndk/ndk/sysroot/usr/include/android/hardware_buffer.h:320:3: note: 'AHardwareBuffer_Plane' declared here} AHardwareBuffer_Plane;
  ^
tensorflow/lite/delegates/gpu/delegate.cc:794:9: error: use of undeclared identifier 'AHardwareBuffer_release'; did you mean 'AHardwareBuffer_Plane'?
        AHardwareBuffer_release(b);
        ^
external/androidndk/ndk/sysroot/usr/include/android/hardware_buffer.h:320:3: note: 'AHardwareBuffer_Plane' declared here} AHardwareBuffer_Plane;
  ^
tensorflow/lite/delegates/gpu/delegate.cc:802:7: error: use of undeclared identifier 'AHardwareBuffer_describe'
      AHardwareBuffer_describe(uptr_ahwb.get(), &desc_ahwb);
      ^
tensorflow/lite/delegates/gpu/delegate.cc:1184:18: error: use of undeclared identifier 'AHardwareBuffer_lock'
          return AHardwareBuffer_lock(buffer, this->usage_, -1 /* fence */,
                 ^
tensorflow/lite/delegates/gpu/delegate.cc:1211:24: error: use of undeclared identifier 'AHardwareBuffer_unlock'
                return AHardwareBuffer_unlock(buffer, nullptr /* fence */);
                       ^
5 errors generated.
```

OS:
```
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal
``` Hi @ValYouW, I encountered the same problem, did you solve it? @colorjam No :( @colorjam I'm back at it today and I was able to resolve the issue, you need to specify that the min NDK version to use is 26 (don't confuse it with ANDROID_SDK_API_LEVEL, which is what I did...).
I just set these env vars on my bashrc
```
export ANDROID_SDK_HOME="<path to where my android sdk is>"
export ANDROID_NDK_HOME="<my android sdk home>/android-ndk-r21e"
export ANDROID_NDK_API_LEVEL="26"
export ANDROID_BUILD_TOOLS_VERSION="34.0.0"
export ANDROID_SDK_API_LEVEL="34"
```
-   **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: macOS Monterey(12.6)
-   **TensorFlow installed from (source or binary)**: Source
-   **Python version**: 3.9.13
-   **Bazel version (if compiling from source)**: 5.3.0
-   **GCC/Compiler version (if compiling from source)**: Apple clang version 14.0.0 (clang-1400.0.29.202)
-   **Exact command to reproduce**: bazel build -c opt --config=android_arm64 --cpu=arm64-v8a //tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_delegate.so

### Describe the problem
Not able to build dynamic tensorflow lite library with gpu delegate for android arm 64. Other tensorflow lite libraries with nnapi, xnnpack delegates are building fine.
### Error
tensorflow/lite/delegates/gpu/delegate.cc:796:7: error: use of undeclared identifier 'AHardwareBuffer_acquire'; did you mean 'AHardwareBuffer_Plane'?
      AHardwareBuffer_acquire(ahwb);
      ^
external/androidndk/ndk/sysroot/usr/include/android/hardware_buffer.h:320:3: note: 'AHardwareBuffer_Plane' declared here
} AHardwareBuffer_Plane;
  ^
tensorflow/lite/delegates/gpu/delegate.cc:804:9: error: use of undeclared identifier 'AHardwareBuffer_release'; did you mean 'AHardwareBuffer_Plane'?
        AHardwareBuffer_release(b);
        ^
external/androidndk/ndk/sysroot/usr/include/android/hardware_buffer.h:320:3: note: 'AHardwareBuffer_Plane' declared here
} AHardwareBuffer_Plane;
  ^
tensorflow/lite/delegates/gpu/delegate.cc:812:7: error: use of undeclared identifier 'AHardwareBuffer_describe'
      AHardwareBuffer_describe(uptr_ahwb.get(), &desc_ahwb);
      ^
tensorflow/lite/delegates/gpu/delegate.cc:1194:18: error: use of undeclared identifier 'AHardwareBuffer_lock'
          return AHardwareBuffer_lock(buffer, this->usage_, -1 /* fence */,
                 ^
tensorflow/lite/delegates/gpu/delegate.cc:1221:24: error: use of undeclared identifier 'AHardwareBuffer_unlock'
                return AHardwareBuffer_unlock(buffer, nullptr /* fence */);
                       ^
5 errors generated.
Target //tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_delegate.so failed to build
