Skip to content

Commit 7fc476e

Browse files
authored
Update examples to use the Starlark version of the Android rules. (#457)
Also disable a windows test until rules_android adds windows support Fixes #454.
1 parent 4679b39 commit 7fc476e

File tree

8 files changed

+70
-29
lines changed

8 files changed

+70
-29
lines changed

.bazelci/android.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
common:
33
android-firebase: &android-firebase
44
name: "Android Firebase Cloud Messaging"
5-
bazel: last_green
5+
bazel: 7.2.0rc1
66
working_directory: ../android/firebase-cloud-messaging
7-
build_flags:
8-
- "--android_platforms=//:arm64-v8a"
97
build_targets:
108
- "//app:app"
119
android-ndk: &android-ndk
1210
name: "Android NDK"
13-
bazel: 6.3.2
11+
bazel: 7.2.0rc1
1412
working_directory: ../android/ndk
1513
build_flags:
1614
- "--android_platforms=//:arm64-v8a,//:x86"
@@ -48,9 +46,11 @@ tasks:
4846
android-firebase-macos:
4947
platform: macos
5048
<<: *android-firebase
51-
android-firebase-windows:
52-
platform: windows
53-
<<: *android-firebase
49+
# rules_android doesn't support windows yet.
50+
# https://github.com/bazelbuild/rules_android/issues/72
51+
# android-firebase-windows:
52+
# platform: windows
53+
# <<: *android-firebase
5454
android-ndk-linux:
5555
platform: ubuntu1804
5656
environment:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
common --experimental_google_legacy_api
2+
common --experimental_enable_android_migration_apis
3+
# Necesary until bazel 7.2.0rc2 or later is released (https://github.com/bazelbuild/bazel/issues/22415)
4+
common --nocheck_visibility
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.2.0rc1

android/firebase-cloud-messaging/WORKSPACE

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
# FIXME(alexeagle): move to bzlmod
22
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
33

4-
# Requires ANDROID_HOME set to the path of your Android SDK.
5-
android_sdk_repository(name = "androidsdk")
6-
7-
android_ndk_repository(name = "androidndk")
8-
94
RULES_JVM_EXTERNAL_TAG = "5.3"
105

116
RULES_JVM_EXTERNAL_SHA = "d31e369b854322ca5098ea12c69d7175ded971435e55c18dd9dd5f29cc5249ac"
@@ -27,7 +22,6 @@ maven_install(
2722
"com.android.support.constraint:constraint-layout:1.0.2",
2823
"com.google.code.gson:gson:2.8.2",
2924
],
30-
fetch_sources = True,
3125
# See https://github.com/bazelbuild/rules_jvm_external/#repository-aliases
3226
# This can be removed if none of your external dependencies uses `maven_jar`.
3327
generate_compat_repositories = True,
@@ -37,6 +31,8 @@ maven_install(
3731
"https://repo1.maven.org/maven2",
3832
],
3933
version_conflict_policy = "pinned",
34+
use_starlark_android_rules = True,
35+
aar_import_bzl_label = "@rules_android//rules:rules.bzl",
4036
)
4137

4238
load("@maven//:compat.bzl", "compat_repositories")
@@ -55,16 +51,27 @@ http_archive(
5551
url = "https://github.com/bazelbuild/tools_android/archive/%s.tar.gz" % TOOLS_ANDROID_COMMIT,
5652
)
5753

54+
RULES_ANDROID_COMMIT = "93e27030d3f0defa39cbbc35195638cb772b0c27"
55+
5856
http_archive(
5957
name = "rules_android",
60-
sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806",
61-
strip_prefix = "rules_android-0.1.1",
62-
urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"],
58+
sha256 = "71cae2413868a24f17d43fd595af6f3905d2e5b3235f76514f54800bfd90c903",
59+
strip_prefix = "rules_android-" + RULES_ANDROID_COMMIT,
60+
urls = ["https://github.com/bazelbuild/rules_android/archive/%s.zip" % RULES_ANDROID_COMMIT],
6361
)
6462

65-
http_archive(
66-
name = "rules_cc",
67-
sha256 = "5f862a44bbd032e1b48ed53c9c211ba2a1da60e10c5baa01c97369c249299ecb",
68-
strip_prefix = "rules_cc-c8c38f8c710cbbf834283e4777916b68261b359c",
69-
url = "https://github.com/bazelbuild/rules_cc/archive/c8c38f8c710cbbf834283e4777916b68261b359c.zip",
63+
load("@rules_android//:prereqs.bzl", "rules_android_prereqs")
64+
rules_android_prereqs()
65+
load("@rules_android//:defs.bzl", "rules_android_workspace")
66+
rules_android_workspace()
67+
68+
load("@rules_android//rules:rules.bzl", "android_sdk_repository")
69+
# Requires that the ANDROID_HOME environment variable is set to the Android SDK path.
70+
android_sdk_repository(
71+
name = "androidsdk",
72+
)
73+
74+
register_toolchains(
75+
"@rules_android//toolchains/android:android_default_toolchain",
76+
"@rules_android//toolchains/android_sdk:android_sdk_tools",
7077
)

android/ndk/.bazelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
common --experimental_google_legacy_api
2+
common --experimental_enable_android_migration_apis
3+
# Necesary until bazel 7.2.0rc2 or later is released (https://github.com/bazelbuild/bazel/issues/22415)
4+
common --nocheck_visibility

android/ndk/.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
6.4.0
1+
7.2.0rc1
22

android/ndk/MODULE.bazel

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
"Bazel dependencies"
22

33
bazel_dep(name = "platforms", version = "0.0.10")
4-
bazel_dep(name = "rules_android", version = "0.1.1")
54
bazel_dep(name = "rules_jvm_external", version = "5.3")
5+
bazel_dep(name = "rules_cc", version = "0.0.9")
6+
7+
bazel_dep(name = "rules_android", version = "0.1.1")
8+
git_override(
9+
module_name = "rules_android",
10+
remote = "https://github.com/bazelbuild/rules_android",
11+
commit = "93e27030d3f0defa39cbbc35195638cb772b0c27",
12+
)
613

714
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
815
maven.install(
@@ -23,5 +30,7 @@ maven.install(
2330
"https://maven.google.com",
2431
"https://repo1.maven.org/maven2",
2532
],
33+
use_starlark_android_rules = True,
34+
aar_import_bzl_label = "@rules_android//rules:rules.bzl",
2635
)
2736
use_repo(maven, "maven")

android/ndk/WORKSPACE

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
22

3+
RULES_ANDROID_COMMIT = "93e27030d3f0defa39cbbc35195638cb772b0c27"
4+
35
http_archive(
4-
name = "build_bazel_rules_android",
5-
sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806",
6-
strip_prefix = "rules_android-0.1.1",
7-
urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"],
6+
name = "rules_android",
7+
sha256 = "71cae2413868a24f17d43fd595af6f3905d2e5b3235f76514f54800bfd90c903",
8+
strip_prefix = "rules_android-" + RULES_ANDROID_COMMIT,
9+
urls = ["https://github.com/bazelbuild/rules_android/archive/%s.zip" % RULES_ANDROID_COMMIT],
810
)
911

10-
load("@build_bazel_rules_android//android:rules.bzl", "android_sdk_repository")
12+
load("@rules_android//:prereqs.bzl", "rules_android_prereqs")
13+
rules_android_prereqs()
14+
load("@rules_android//:defs.bzl", "rules_android_workspace")
15+
rules_android_workspace()
1116

12-
android_sdk_repository(name = "androidsdk")
17+
load("@rules_android//rules:rules.bzl", "android_sdk_repository")
18+
# Requires that the ANDROID_HOME environment variable is set to the Android SDK path.
19+
android_sdk_repository(
20+
name = "androidsdk",
21+
)
22+
23+
register_toolchains(
24+
"@rules_android//toolchains/android:android_default_toolchain",
25+
"@rules_android//toolchains/android_sdk:android_sdk_tools",
26+
)
1327

1428
http_archive(
1529
name = "rules_android_ndk",
@@ -21,3 +35,5 @@ http_archive(
2135
load("@rules_android_ndk//:rules.bzl", "android_ndk_repository")
2236

2337
android_ndk_repository(name = "androidndk")
38+
39+
register_toolchains("@androidndk//:all")

0 commit comments

Comments
 (0)