@@ -46,16 +46,31 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [
4646]
4747# GRPC_DEPS_END
4848
49+ ANDROID_ARTIFACTS = [
50+ "androidx.annotation:annotation:1.6.0" ,
51+ "androidx.annotation:annotation-jvm:1.6.0" ,
52+ "androidx.core:core:1.13.1" ,
53+ "androidx.lifecycle:lifecycle-common:2.6.2" ,
54+ ]
55+
4956bazel_dep (name = "abseil-cpp" , version = "20250512.1" )
5057bazel_dep (name = "bazel_jar_jar" , version = "0.1.11.bcr.1" )
5158bazel_dep (name = "bazel_skylib" , version = "1.7.1" )
5259bazel_dep (name = "googleapis" , version = "0.0.0-20240326-1c8d509c5" , repo_name = "com_google_googleapis" )
5360bazel_dep (name = "grpc-proto" , version = "0.0.0-20240627-ec30f58.bcr.1" , repo_name = "io_grpc_grpc_proto" )
5461bazel_dep (name = "protobuf" , version = "33.4" , repo_name = "com_google_protobuf" )
62+ bazel_dep (name = "rules_android" , version = "0.7.2" )
5563bazel_dep (name = "rules_cc" , version = "0.0.9" )
5664bazel_dep (name = "rules_java" , version = "9.1.0" )
5765bazel_dep (name = "rules_jvm_external" , version = "6.0" )
5866
67+ android_sdk_repository_extension = use_extension (
68+ "@rules_android//rules/android_sdk_repository:rule.bzl" ,
69+ "android_sdk_repository_extension" ,
70+ )
71+ use_repo (android_sdk_repository_extension , "androidsdk" )
72+ register_toolchains ("@androidsdk//:sdk-toolchain" , "@androidsdk//:all" )
73+
5974maven = use_extension ("@rules_jvm_external//:extensions.bzl" , "maven" )
6075maven .install (
6176 artifacts = IO_GRPC_GRPC_JAVA_ARTIFACTS ,
@@ -64,7 +79,36 @@ maven.install(
6479 ],
6580 strict_visibility = True ,
6681)
67- use_repo (maven , "maven" )
82+
83+ # We isolate Android-specific deps in this separate repo ('grpc_android_maven') instead of the one
84+ # above (having default name 'maven').
85+ #
86+ # Under bzlmod, rules_jvm_external merges all contributions to the same named repository (like the
87+ # default 'maven' repo) across the entire dependency graph. If we put Android dependencies there,
88+ # then *every* downstream consumer's merged 'maven' repository would include these Android
89+ # artifacts.
90+ #
91+ # Because merged repositories are resolved using only the root module's (the consumer's)
92+ # repository list, any consumer without 'maven.google.com' configured in their root module
93+ # would fail to resolve these artifacts, breaking their build even if they don't use Android.
94+ #
95+ # By using a distinct name ('grpc_android_maven'), we prevent merging. This repository is resolved
96+ # independently, allowing it to use grpc-java's own repository config (which includes
97+ # maven.google.com) without affecting downstream consumers' default 'maven' repo.
98+ maven .install (
99+ name = "grpc_android_maven" ,
100+ artifacts = ANDROID_ARTIFACTS ,
101+ repositories = [
102+ "https://repo.maven.apache.org/maven2/" ,
103+ "https://maven.google.com" , # for androidx.*
104+ ],
105+ strict_visibility = True ,
106+ # Enable Starlark Android rules in rules_jvm_external for Bazel 8+ compatibility.
107+ use_starlark_android_rules = True ,
108+ # Explicitly set the label for aar_import since the default guess is incorrect under Bzlmod.
109+ aar_import_bzl_label = "@rules_android//rules:rules.bzl" ,
110+ )
111+ use_repo (maven , "maven" , "grpc_android_maven" )
68112
69113maven .override (
70114 coordinates = "com.google.protobuf:protobuf-java" ,
@@ -158,3 +202,7 @@ maven.override(
158202 coordinates = "io.grpc:grpc-util" ,
159203 target = "@io_grpc_grpc_java//util" ,
160204)
205+ maven .override (
206+ coordinates = "io.grpc:grpc-binder" ,
207+ target = "@io_grpc_grpc_java//binder" ,
208+ )
0 commit comments