-
Notifications
You must be signed in to change notification settings - Fork 87
Protobuf gencode/runtime version mismatch in ResourceProcessorBusyBox when protobuf module resolves to any version > 33.4 #498
Description
Problem
When the Bazel module graph resolves protobuf to any version newer than 33.4 (e.g., 34.0, 35.0, etc.) via MVS, the ResourceProcessorBusyBox tool fails at runtime with a ProtobufRuntimeVersionException:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.google.devtools.build.android.DataResourceXml1ドル.<clinit>(DataResourceXml.java:199)
...
Caused by: com.google.protobuf.RuntimeVersion$ProtobufRuntimeVersionException:
Detected incompatible Protobuf Gencode/Runtime versions when loading XmlType:
gencode 4.34.0, runtime 4.33.4. Runtime version cannot be older than the linked gencode version.
at com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersionImpl(RuntimeVersion.java:153)
at com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion(RuntimeVersion.java:72)
at com.google.devtools.build.android.proto.SerializeFormat$DataValueXml$XmlType.<clinit>(SerializeFormat.java:4134)
Root Cause
rules_android declares bazel_dep(name = "protobuf", version = "33.4") in its MODULE.bazel, and hardcodes com.google.protobuf:protobuf-java:4.33.4 in both its rules_android_maven and android_ide_common_30_1_3 Maven installs.
However, the serialize_format_java_pb target in //src/tools/java/com/google/devtools/build/android/proto is compiled using @com_google_protobuf//bazel:java_proto_library.bzl, which uses whatever version of protobuf the module graph ultimately resolves to via MVS. Since rules_android does not control the final resolved version, any other module in the graph that requires protobuf > 33.4 will trigger this failure.
This creates a mismatch:
- Proto compiler (gencode): Uses the MVS-resolved protobuf version (e.g.,
34.0,35.0, etc.) → generates Java code stamped with that version - Runtime jar:
@rules_android_maven//:com_google_protobuf_protobuf_javais pinned to4.33.4
Since protobuf enforces runtime >= gencode, the tool crashes whenever the resolved protobuf module is newer than 33.4.
Affected Targets
Any aar_import or Android resource merging action that invokes ResourceProcessorBusyBox.
Reproduction
This will occur whenever any module in the dependency graph transitively requires protobuf > 33.4. This is increasingly common as many BCR modules have already updated their protobuf dependency. Examples of modules that pull in protobuf@34.0:
rules_swift@3.5.0
Suggested Fix
Bump the bazel_dep for protobuf and the corresponding protobuf-java / protobuf-java-util Maven pins in rules_android's MODULE.bazel to a current version (e.g., 34.0 / 4.34.0).
Workaround
Users can work around this by using single_version_override on protobuf, but this has chances of breaking other libraries that depend on the newer version.
Environment
- Bazel 9.1.0
rules_android0.7.2protobufresolved to34.0.bcr.1via MVS (any version > 33.4 triggers the issue)