Protocol Buffers - Google's data interchange format (grpc依赖) https://developers.google.com/protocol-buffers/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
2.1 KiB

# Protocol Buffers - Google's data interchange format
Copyright 2008 Google Inc.
https://developers.google.com/protocol-buffers/
## Use the Protobuf Java Lite Runtime
The Protobuf Java Lite runtime is separated from the main Java runtime because
it's designed and implemented with different constraints. In particular, the Java
Lite runtime is much smaller which makes it more suitable to be used on Android.
In order to achieve maximum performance and code size, we do
NOT guarantee API/ABI stability for Java Lite. If this is not acceptable
for your use-case, use the full Java runtime instead. Note that
the latest version of Java Lite is not compatible with the 3.0.0 version.
You can generate Java Lite code for your .proto files:
$ protoc --java_out=lite:${OUTPUT_DIR} path/to/your/proto/file
The "optimize_for = LITE_RUNTIME" option in the .proto file no longer has any
effect on Java code.
Include the generated Java files in your project and add a dependency on the
protobuf Java Lite runtime. If you are using Maven, include the following:
```xml
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-javalite</artifactId>
Merge 21.8 into main (#10788) * Force uninstall protobuf in python macos builds We are seeing failures in brew uninstall protobuf due to no package. Change this to a force install to avoid the error. * Fix spelling errors (#10717) * Merge pull request #10200 from tonydnewell/bugfix/protobuf-7474 Fix for grpc.tools #17995 & protobuf #7474 (handle UTF-8 paths in argumentfile) * Upgrade to kotlin 1.6 * 21.x No longer define no_threadlocal on OpenBSD * Upgrade kokoro to Xcode 14 (#10732) * Upgrade kokoro to Xcode 14 * Fix osx errors * Merge pull request #10770 from protocolbuffers/googleberg-cl-480629524 Mark default instance as immutable first to avoid race during static initialization of default instances. * Auto capitalize enums name in Ruby (#10454) (#10763) This closes #1965. * Edit toolchain to work with absl dep * Bump upb to latest version after fixes applied (#10783) * 21.x 202210180838 (#10785) * Updating version.json and repo version numbers to: 21.8 * Update changelog Co-authored-by: Protobuf Team Bot <protobuf-team-bot@google.com> * Update generated protos Co-authored-by: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Co-authored-by: Matt Fowles Kulukundis <matt.fowles@gmail.com> Co-authored-by: Deanna Garcia <deannagarcia@google.com> Co-authored-by: Brad Smith <brad@comstyle.com> Co-authored-by: Jerry Berg <107155935+googleberg@users.noreply.github.com> Co-authored-by: tison <wander4096@gmail.com> Co-authored-by: Protobuf Team Bot <protobuf-team-bot@google.com>
2 years ago
<version>3.21.8</version>
</dependency>
```
## R8 rule to make production app builds work
The Lite runtime internally uses reflection to avoid generating hashCode/equals/(de)serialization methods.
R8 by default obfuscates the field names, which makes the reflection fail causing exceptions of the form
`java.lang.RuntimeException: Field {NAME}_ for {CLASS} not found. Known fields are [ {FIELDS} ]` in MessageSchema.java.
There are open issues for this on the [protobuf Github project](https://github.com/protocolbuffers/protobuf/issues/6463) and [R8](https://issuetracker.google.com/issues/144631039).
Until the issues is resolved you need to add the following line to your `proguard-rules.pro` file inside your project:
```
-keep class * extends com.google.protobuf.GeneratedMessageLite { *; }
```
## Older versions
For the older version of Java Lite (v3.0.0), please refer to:
https://github.com/protocolbuffers/protobuf/blob/javalite/java/lite.md