google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://mediapipe.dev
Apache License 2.0
26.71k stars 5.08k forks source link

bazel build error for 'android_arm64' #5540

Closed Ramees025 closed 3 weeks ago

Ramees025 commented 1 month ago

OS Platform and Distribution

Ubuntu

Compiler version

No response

Programming Language and version

c++

Installed using virtualenv? pip? Conda?(if python)

No response

MediaPipe version

No response

Bazel version

No response

XCode and Tulsi versions (if iOS)

No response

Android SDK and NDK versions (if android)

r21e

Android AAR (if android)

None

OpenCV version (if running on desktop)

No response

Describe the problem

ERROR: An error occurred during the fetch of repository 'androidndk':

Complete Logs

When running below command, 
bazel build --cxxopt=-DABSL_FLAGS_STRIP_NAMES=0 -c opt --config=android_arm64 mediapipe/tasks/cc/genai/inference/c:llm_inference_engine_cpu_main

I am getting below error,

test@NEURAL-PLATFORM:~/ARM/mediapipe$ bazel build --cxxopt=-DABSL_FLAGS_STRIP_NAMES=0 -c opt --config=android_arm64 mediapipe/tasks/cc/genai/inference/c:llm_inference_engine_cpu_main
INFO: Build options --compilation_mode, --cpu, --crosstool_top, and 5 more have changed, discarding analysis cache.
INFO: Repository androidndk instantiated at:
  /home/test/ARM/mediapipe/WORKSPACE:713:23: in <toplevel>
Repository rule android_ndk_repository defined at:
  /home/test/.cache/bazel/_bazel_test/595332dd80a1b8d4c4daca7eb4d09658/external/rules_android_ndk/rules.bzl:127:41: in <toplevel>
ERROR: An error occurred during the fetch of repository 'androidndk':
   Traceback (most recent call last):
        File "/home/test/.cache/bazel/_bazel_test/595332dd80a1b8d4c4daca7eb4d09658/external/rules_android_ndk/rules.bzl", line 49, column 21, in _android_ndk_repository_impl
                _create_symlinks(ctx, ndk_path, clang_directory, sysroot_directory)
        File "/home/test/.cache/bazel/_bazel_test/595332dd80a1b8d4c4daca7eb4d09658/external/rules_android_ndk/rules.bzl", line 116, column 24, in _create_symlinks
                ctx.symlink(p, repo_relative_path)
Error in symlink: Cannot write outside of the repository directory for path /home/test/Android/Sdk/ndk-bundle/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/libexec
ERROR: /home/test/ARM/mediapipe/WORKSPACE:713:23: fetching android_ndk_repository rule //external:androidndk: Traceback (most recent call last):
        File "/home/test/.cache/bazel/_bazel_test/595332dd80a1b8d4c4daca7eb4d09658/external/rules_android_ndk/rules.bzl", line 49, column 21, in _android_ndk_repository_impl
                _create_symlinks(ctx, ndk_path, clang_directory, sysroot_directory)
        File "/home/test/.cache/bazel/_bazel_test/595332dd80a1b8d4c4daca7eb4d09658/external/rules_android_ndk/rules.bzl", line 116, column 24, in _create_symlinks
                ctx.symlink(p, repo_relative_path)
Error in symlink: Cannot write outside of the repository directory for path /home/test/Android/Sdk/ndk-bundle/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/libexec
INFO: Repository flatbuffers instantiated at:
  /home/test/ARM/mediapipe/WORKSPACE:284:12: in <toplevel>
  /home/test/ARM/mediapipe/third_party/flatbuffers/workspace.bzl:6:29: in repo
Repository rule third_party_http_archive defined at:
  /home/test/ARM/mediapipe/third_party/repo.bzl:132:43: in <toplevel>
INFO: Repository com_google_sentencepiece instantiated at:
  /home/test/ARM/mediapipe/WORKSPACE:305:13: in <toplevel>
Repository rule http_archive defined at:
  /home/test/.cache/bazel/_bazel_test/595332dd80a1b8d4c4daca7eb4d09658/external/bazel_tools/tools/build_defs/repo/http.bzl:372:31: in <toplevel>
ERROR: /home/test/ARM/mediapipe/WORKSPACE:714:5: //external:android/crosstool depends on @androidndk//:toolchain in repository @androidndk which failed to fetch. no such package '@androidndk//': Cannot write outside of the repository directory for path /home/test/Android/Sdk/ndk-bundle/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/libexec
ERROR: Analysis of target '//mediapipe/tasks/cc/genai/inference/c:llm_inference_engine_cpu_main' failed; build aborted:
INFO: Elapsed time: 3.032s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (4 packages loaded, 220 targets configured)
    currently loading: mediapipe/tasks/cc/genai/inference/utils/xnn_utils
    Fetching repository @com_github_glog_glog_no_gflags; starting
    Fetching /home/test/.cache/bazel/_bazel_test/595332dd80a1b8d4c4daca7eb4d09658/external/com_github_glog_glog_no_gflags; Extracting v0.6.0.tar.gz

Any idea how to solve this?
Ramees025 commented 1 month ago

ERROR: An error occurred during the fetch of repository 'androidndk': Traceback (most recent call last): File "/home/test/.cache/bazel/_bazel_test/595332dd80a1b8d4c4daca7eb4d09658/external/rules_android_ndk/rules.bzl", line 49, column 21, in _android_ndk_repository_impl _create_symlinks(ctx, ndk_path, clang_directory, sysroot_directory) File "/home/test/.cache/bazel/_bazel_test/595332dd80a1b8d4c4daca7eb4d09658/external/rules_android_ndk/rules.bzl", line 116, column 24, in _create_symlinks ctx.symlink(p, repo_relative_path) Error in symlink: Cannot write outside of the repository directory for path /home/test/Android/Sdk/ndk-bundle/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/libexec

kuaashish commented 1 month ago

Hi @Ramees025,

Please run this command after navigating to the MediaPipe cloned repository on your local machine and let us know if you can build it successfully.

chmod +x setup_android_sdk_and_ndk.sh
./setup_android_sdk_and_ndk.sh

Thank you!!

Siddharth-Latthe-07 commented 1 month ago

The error message you're encountering suggests that Bazel is attempting to create symlinks outside of the repository directory, which is not allowed. Steps to resolve the issue:-

  1. Check NDK Path: Ensure that the NDK path in your WORKSPACE file is correctly set and points to a valid NDK installation. The path should not include the symlinks that Bazel is attempting to create.
    android_ndk_repository(
    name = "androidndk",
    path = "/home/test/Android/Sdk/ndk/21.4.7075529",  # Update with your actual path
    )
  2. Update NDK
  3. Check Permissions: Ensure that you have the necessary permissions to access and write to the directories involved. This includes the Bazel cache directory and the NDK directory.
    sudo chown -R $(whoami) /home/test/Android/Sdk/ndk-bundle
    sudo chown -R $(whoami) /home/test/.cache/bazel

    4.Use Correct Bazel Version: Ensure you are using a compatible version of Bazel. MediaPipe might require a specific version. Check MediaPipe's documentation for the recommended Bazel version and install it. 5, Clean Bazel Cache: Sometimes, Bazel's cache might be corrupted or outdated. Cleaning the cache might resolve the issue.

    bazel clean --expunge
  4. Check WORKSPACE Configuration: Ensure your WORKSPACE file has the correct configuration for the Android NDK. sample snippet:-
    android_ndk_repository(
    name = "androidndk",
    path = "/home/test/Android/Sdk/ndk/21.4.7075529",  # Update this path
    api_level = 21  # Or your desired API level
    )
  5. lastly, Final Command Once all configurations are corrected, try running the build command again:
    bazel build --cxxopt=-DABSL_FLAGS_STRIP_NAMES=0 -c opt --config=android_arm64 mediapipe/tasks/cc/genai/inference/c:llm_inference_engine_cpu_main

Hope this helps, Thanks

kuaashish commented 1 month ago

Hi @Ramees025.

Can you please go through the above comment https://github.com/google-ai-edge/mediapipe/issues/5540#issuecomment-2244364781 and let us know the status of this?

Thank you!!

github-actions[bot] commented 1 month ago

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

github-actions[bot] commented 3 weeks ago

This issue was closed due to lack of activity after being marked stale for past 7 days.

google-ml-butler[bot] commented 3 weeks ago

Are you satisfied with the resolution of your issue? Yes No