How to build tensorflow lite support library for android in Docker

Hi,

I referred to Tensorflow official tutorial to build support library. Build TensorFlow Lite for Android

I updated the bazel version to 6.5.0.
This is partial of my bazelrc config in tflite-support.

build --action_env PYTHON_BIN_PATH=“/usr/bin/python3”
build --action_env PYTHON_LIB_PATH=“/usr/lib/python3/dist-packages”
build --python_path=“/usr/bin/python3”
build --action_env CLANG_COMPILER_PATH=“/usr/lib/llvm-17/bin/clang”
build --repo_env=CC=/usr/lib/llvm-17/bin/clang
build --repo_env=BAZEL_COMPILER=/usr/lib/llvm-17/bin/clang

build --action_env ANDROID_NDK_HOME=“/android/android-ndk-r21e”
build --action_env ANDROID_NDK_API_LEVEL=“21”
build --action_env ANDROID_BUILD_TOOLS_VERSION=“31.0.0”
build --action_env ANDROID_SDK_API_LEVEL=“30”
build --action_env ANDROID_SDK_HOME=“/android/sdk”

When I build with this command “bazel build --fat_apk_cpu=‘arm64-v8a,armeabi-v7a’ //tensorflow_lite_support/java:tensorflowlite_support”, I encounter the following error.

ERROR: /root/.cache/bazel/_bazel_root/5d46a502f524e2d7880e9b6390ac3cfe/external/org_tensorflow/tensorflow/lite/java/BUILD:1006:23: Linking external/org_tensorflow/tensorflow/lite/java/libtensorflowlite_jni_stable.so failed: (Exit 1): clang failed: error executing command (from target @org_tensorflow//tensorflow/lite/java:libtensorflowlite_jni_stable.so) /usr/lib/llvm-17/bin/clang @bazel-out/k8-opt/bin/external/org_tensorflow/tensorflow/lite/java/libtensorflowlite_jni_stable.so-2.params
ld.lld: error: version script assignment of ‘VERS_1.0’ to symbol ‘JNI_OnLoad’ failed: symbol not defined
ld.lld: error: version script assignment of ‘VERS_1.0’ to symbol ‘JNI_OnUnload’ failed: symbol not defined
ld.lld: error: version script assignment of ‘VERS_1.0’ to symbol ‘google_find_phdr’ failed: symbol not defined
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Target //tensorflow_lite_support/java:tensorflowlite_support failed to build

What should I adjust?

Hi @Jack_Lai ,

As per my understanding, these commands build the environment without Docker. The error log indicates that the symbols JNI_OnLoad , JNI_OnUnload , and google_find_phdr were not found by the linker during the build process. First, ensure that these symbols are defined in the native C++ code. Next, verify that the ANDROID_NDK_HOME path points to the correct NDK installation. To provide more context, please share the complete error log by running bazel build --verbose_failures //tensorflow_lite_support/java:tensorflowlite_support .

Thank You