diff options
author | Vinh Tran <vinhdaitran@google.com> | 2024-01-15 22:51:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-16 03:51:42 +0000 |
commit | d48f73195b529b86cae3436bcd8577bc368f8863 (patch) | |
tree | 2fe3723e56d2124c388650282640fd3ef26cb370 | |
parent | d72f4a8c7bd1151bfb1ef0fdd300bb69bd4dde2a (diff) | |
download | bazelbuild-rules_rust-d48f73195b529b86cae3436bcd8577bc368f8863.tar.gz |
Update android example to use Starlark version of android_ndk_repository (#2417)
The native version of `android_ndk_repository` rule no longer work with
the newer ndk versions.
When I set `ANDROID_NDK_HOME` to
`/usr/local/vinhdaitran/Android/Sdk/ndk/26.1.10909125`, the rule expects
a different structure from the Android NDK path.
```
ERROR: /usr/local/vinhdaitran/github/rules_rust/examples/android/WORKSPACE.bazel:67:23: fetching android_ndk_repository rule //external:androidndk: java.io.IOException:
Expected directory at /usr/local/vinhdaitran/Android/Sdk/ndk/26.1.10909125/platforms but it is not a directory or it does not exist.
Unable to read the Android NDK at /usr/local/vinhdaitran/Android/Sdk/ndk/26.1.10909125, the path may be invalid. Is the path in android_ndk_repository() or ANDROID_NDK_HOME set correctly?
If the path is correct, the contents in the Android NDK directory may have been modified.
```
Using the Starlark version of the rule, as recommended in
https://bazel.build/reference/be/android#android_ndk_repository, fixes
the issue.
cc: @keith
-rw-r--r-- | .bazelci/presubmit.yml | 12 | ||||
-rw-r--r-- | examples/android/.bazelrc | 2 | ||||
-rw-r--r-- | examples/android/WORKSPACE.bazel | 17 |
3 files changed, 28 insertions, 3 deletions
diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 9bef3980..6281c449 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -581,6 +581,12 @@ tasks: - "--android_platforms=//:arm64-v8a" build_targets: - "//:android_app" + environment: + # This ndk version matches with rules_android_ndk repo's CI + # https://github.com/bazelbuild/rules_android_ndk/blob/877c68ef34c9f3353028bf490d269230c1990483/.bazelci/presubmit.yml#L37 + # The ndk is installed by this script + # https://github.com/bazelbuild/continuous-integration/blob/ba56013373821feadd9f2eaa6b81eb19528795f0/macos/mac-android.sh + ANDROID_NDK_HOME: /opt/android-ndk-r25b android_examples_macos: name: Android Examples platform: macos @@ -591,6 +597,12 @@ tasks: - "--android_platforms=//:arm64-v8a" build_targets: - "//:android_app" + environment: + # This ndk version matches with rules_android_ndk repo's CI + # https://github.com/bazelbuild/rules_android_ndk/blob/877c68ef34c9f3353028bf490d269230c1990483/.bazelci/presubmit.yml#L42 + # The ndk is installed by this script + # https://github.com/bazelbuild/continuous-integration/blob/ba56013373821feadd9f2eaa6b81eb19528795f0/macos/mac-android.sh + ANDROID_NDK_HOME: /Users/buildkite/android-ndk-r25b ios_examples: name: iOS Examples platform: macos diff --git a/examples/android/.bazelrc b/examples/android/.bazelrc index d9d2c74e..52bb082c 100644 --- a/examples/android/.bazelrc +++ b/examples/android/.bazelrc @@ -3,7 +3,7 @@ common --enable_platform_specific_config startup --windows_enable_symlinks build:windows --enable_runfiles -build --fat_apk_cpu=arm64-v8a +build --fat_apk_cpu=arm64-v8a --android_crosstool_top=@androidndk//:toolchain # TODO: migrate all dependencies from WORKSPACE to MODULE.bazel # https://github.com/bazelbuild/rules_rust/issues/2181 diff --git a/examples/android/WORKSPACE.bazel b/examples/android/WORKSPACE.bazel index 8b65349e..b3adb9ed 100644 --- a/examples/android/WORKSPACE.bazel +++ b/examples/android/WORKSPACE.bazel @@ -45,6 +45,19 @@ rbe_preconfig( toolchain = "ubuntu1804-bazel-java11", ) -android_sdk_repository(name = "androidsdk") +android_sdk_repository( + name = "androidsdk", +) + +http_archive( + name = "rules_android_ndk", + sha256 = "b1a5ddd784e6ed915c2035c0db536a278b5f50c64412128c06877115991391ef", + strip_prefix = "rules_android_ndk-877c68ef34c9f3353028bf490d269230c1990483", + url = "https://github.com/bazelbuild/rules_android_ndk/archive/877c68ef34c9f3353028bf490d269230c1990483.zip", +) + +load("@rules_android_ndk//:rules.bzl", "android_ndk_repository") -android_ndk_repository(name = "androidndk") +android_ndk_repository( + name = "androidndk", +) |