Skip to content

Commit

Permalink
Update examples to use the Starlark version of the Android rules. (#457)
Browse files Browse the repository at this point in the history
Also disable a windows test until rules_android adds windows support

Fixes #454.
  • Loading branch information
ahumesky authored May 28, 2024
1 parent 4679b39 commit 7fc476e
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 29 deletions.
14 changes: 7 additions & 7 deletions .bazelci/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
common:
android-firebase: &android-firebase
name: "Android Firebase Cloud Messaging"
bazel: last_green
bazel: 7.2.0rc1
working_directory: ../android/firebase-cloud-messaging
build_flags:
- "--android_platforms=//:arm64-v8a"
build_targets:
- "//app:app"
android-ndk: &android-ndk
name: "Android NDK"
bazel: 6.3.2
bazel: 7.2.0rc1
working_directory: ../android/ndk
build_flags:
- "--android_platforms=//:arm64-v8a,//:x86"
Expand Down Expand Up @@ -48,9 +46,11 @@ tasks:
android-firebase-macos:
platform: macos
<<: *android-firebase
android-firebase-windows:
platform: windows
<<: *android-firebase
# rules_android doesn't support windows yet.
# https://github.com/bazelbuild/rules_android/issues/72
# android-firebase-windows:
# platform: windows
# <<: *android-firebase
android-ndk-linux:
platform: ubuntu1804
environment:
Expand Down
4 changes: 4 additions & 0 deletions android/firebase-cloud-messaging/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
common --experimental_google_legacy_api
common --experimental_enable_android_migration_apis
# Necesary until bazel 7.2.0rc2 or later is released (https://github.com/bazelbuild/bazel/issues/22415)
common --nocheck_visibility
1 change: 1 addition & 0 deletions android/firebase-cloud-messaging/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.2.0rc1
35 changes: 21 additions & 14 deletions android/firebase-cloud-messaging/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# FIXME(alexeagle): move to bzlmod
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Requires ANDROID_HOME set to the path of your Android SDK.
android_sdk_repository(name = "androidsdk")

android_ndk_repository(name = "androidndk")

RULES_JVM_EXTERNAL_TAG = "5.3"

RULES_JVM_EXTERNAL_SHA = "d31e369b854322ca5098ea12c69d7175ded971435e55c18dd9dd5f29cc5249ac"
Expand All @@ -27,7 +22,6 @@ maven_install(
"com.android.support.constraint:constraint-layout:1.0.2",
"com.google.code.gson:gson:2.8.2",
],
fetch_sources = True,
# See https://github.com/bazelbuild/rules_jvm_external/#repository-aliases
# This can be removed if none of your external dependencies uses `maven_jar`.
generate_compat_repositories = True,
Expand All @@ -37,6 +31,8 @@ maven_install(
"https://repo1.maven.org/maven2",
],
version_conflict_policy = "pinned",
use_starlark_android_rules = True,
aar_import_bzl_label = "@rules_android//rules:rules.bzl",
)

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

RULES_ANDROID_COMMIT = "93e27030d3f0defa39cbbc35195638cb772b0c27"

http_archive(
name = "rules_android",
sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806",
strip_prefix = "rules_android-0.1.1",
urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"],
sha256 = "71cae2413868a24f17d43fd595af6f3905d2e5b3235f76514f54800bfd90c903",
strip_prefix = "rules_android-" + RULES_ANDROID_COMMIT,
urls = ["https://github.com/bazelbuild/rules_android/archive/%s.zip" % RULES_ANDROID_COMMIT],
)

http_archive(
name = "rules_cc",
sha256 = "5f862a44bbd032e1b48ed53c9c211ba2a1da60e10c5baa01c97369c249299ecb",
strip_prefix = "rules_cc-c8c38f8c710cbbf834283e4777916b68261b359c",
url = "https://github.com/bazelbuild/rules_cc/archive/c8c38f8c710cbbf834283e4777916b68261b359c.zip",
load("@rules_android//:prereqs.bzl", "rules_android_prereqs")
rules_android_prereqs()
load("@rules_android//:defs.bzl", "rules_android_workspace")
rules_android_workspace()

load("@rules_android//rules:rules.bzl", "android_sdk_repository")
# Requires that the ANDROID_HOME environment variable is set to the Android SDK path.
android_sdk_repository(
name = "androidsdk",
)

register_toolchains(
"@rules_android//toolchains/android:android_default_toolchain",
"@rules_android//toolchains/android_sdk:android_sdk_tools",
)
4 changes: 4 additions & 0 deletions android/ndk/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
common --experimental_google_legacy_api
common --experimental_enable_android_migration_apis
# Necesary until bazel 7.2.0rc2 or later is released (https://github.com/bazelbuild/bazel/issues/22415)
common --nocheck_visibility
2 changes: 1 addition & 1 deletion android/ndk/.bazelversion
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
6.4.0
7.2.0rc1

11 changes: 10 additions & 1 deletion android/ndk/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
"Bazel dependencies"

bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_android", version = "0.1.1")
bazel_dep(name = "rules_jvm_external", version = "5.3")
bazel_dep(name = "rules_cc", version = "0.0.9")

bazel_dep(name = "rules_android", version = "0.1.1")
git_override(
module_name = "rules_android",
remote = "https://github.com/bazelbuild/rules_android",
commit = "93e27030d3f0defa39cbbc35195638cb772b0c27",
)

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
Expand All @@ -23,5 +30,7 @@ maven.install(
"https://maven.google.com",
"https://repo1.maven.org/maven2",
],
use_starlark_android_rules = True,
aar_import_bzl_label = "@rules_android//rules:rules.bzl",
)
use_repo(maven, "maven")
28 changes: 22 additions & 6 deletions android/ndk/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

RULES_ANDROID_COMMIT = "93e27030d3f0defa39cbbc35195638cb772b0c27"

http_archive(
name = "build_bazel_rules_android",
sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806",
strip_prefix = "rules_android-0.1.1",
urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"],
name = "rules_android",
sha256 = "71cae2413868a24f17d43fd595af6f3905d2e5b3235f76514f54800bfd90c903",
strip_prefix = "rules_android-" + RULES_ANDROID_COMMIT,
urls = ["https://github.com/bazelbuild/rules_android/archive/%s.zip" % RULES_ANDROID_COMMIT],
)

load("@build_bazel_rules_android//android:rules.bzl", "android_sdk_repository")
load("@rules_android//:prereqs.bzl", "rules_android_prereqs")
rules_android_prereqs()
load("@rules_android//:defs.bzl", "rules_android_workspace")
rules_android_workspace()

android_sdk_repository(name = "androidsdk")
load("@rules_android//rules:rules.bzl", "android_sdk_repository")
# Requires that the ANDROID_HOME environment variable is set to the Android SDK path.
android_sdk_repository(
name = "androidsdk",
)

register_toolchains(
"@rules_android//toolchains/android:android_default_toolchain",
"@rules_android//toolchains/android_sdk:android_sdk_tools",
)

http_archive(
name = "rules_android_ndk",
Expand All @@ -21,3 +35,5 @@ http_archive(
load("@rules_android_ndk//:rules.bzl", "android_ndk_repository")

android_ndk_repository(name = "androidndk")

register_toolchains("@androidndk//:all")

0 comments on commit 7fc476e

Please sign in to comment.