Skip to content

Commit d48f731

Browse files
author
Vinh Tran
authored
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
1 parent d72f4a8 commit d48f731

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

.bazelci/presubmit.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,12 @@ tasks:
581581
- "--android_platforms=//:arm64-v8a"
582582
build_targets:
583583
- "//:android_app"
584+
environment:
585+
# This ndk version matches with rules_android_ndk repo's CI
586+
# https://github.com/bazelbuild/rules_android_ndk/blob/877c68ef34c9f3353028bf490d269230c1990483/.bazelci/presubmit.yml#L37
587+
# The ndk is installed by this script
588+
# https://github.com/bazelbuild/continuous-integration/blob/ba56013373821feadd9f2eaa6b81eb19528795f0/macos/mac-android.sh
589+
ANDROID_NDK_HOME: /opt/android-ndk-r25b
584590
android_examples_macos:
585591
name: Android Examples
586592
platform: macos
@@ -591,6 +597,12 @@ tasks:
591597
- "--android_platforms=//:arm64-v8a"
592598
build_targets:
593599
- "//:android_app"
600+
environment:
601+
# This ndk version matches with rules_android_ndk repo's CI
602+
# https://github.com/bazelbuild/rules_android_ndk/blob/877c68ef34c9f3353028bf490d269230c1990483/.bazelci/presubmit.yml#L42
603+
# The ndk is installed by this script
604+
# https://github.com/bazelbuild/continuous-integration/blob/ba56013373821feadd9f2eaa6b81eb19528795f0/macos/mac-android.sh
605+
ANDROID_NDK_HOME: /Users/buildkite/android-ndk-r25b
594606
ios_examples:
595607
name: iOS Examples
596608
platform: macos

examples/android/.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ common --enable_platform_specific_config
33
startup --windows_enable_symlinks
44
build:windows --enable_runfiles
55

6-
build --fat_apk_cpu=arm64-v8a
6+
build --fat_apk_cpu=arm64-v8a --android_crosstool_top=@androidndk//:toolchain
77

88
# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
99
# https://github.com/bazelbuild/rules_rust/issues/2181

examples/android/WORKSPACE.bazel

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ rbe_preconfig(
4545
toolchain = "ubuntu1804-bazel-java11",
4646
)
4747

48-
android_sdk_repository(name = "androidsdk")
48+
android_sdk_repository(
49+
name = "androidsdk",
50+
)
51+
52+
http_archive(
53+
name = "rules_android_ndk",
54+
sha256 = "b1a5ddd784e6ed915c2035c0db536a278b5f50c64412128c06877115991391ef",
55+
strip_prefix = "rules_android_ndk-877c68ef34c9f3353028bf490d269230c1990483",
56+
url = "https://github.com/bazelbuild/rules_android_ndk/archive/877c68ef34c9f3353028bf490d269230c1990483.zip",
57+
)
58+
59+
load("@rules_android_ndk//:rules.bzl", "android_ndk_repository")
4960

50-
android_ndk_repository(name = "androidndk")
61+
android_ndk_repository(
62+
name = "androidndk",
63+
)

0 commit comments

Comments
 (0)