• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Protocol Buffers - Google's data interchange format
2
3Copyright 2008 Google Inc.
4
5https://developers.google.com/protocol-buffers/
6
7## Use Protobuf Java Lite Runtime
8
9Protobuf Java Lite runtime is separated from the main Java runtime because
10it's designed/implemented with different constraints. In particular, Java
11Lite runtime has a much smaller code size which makes it more suitable to
12be used on Android.
13
14Note that in order to achieve maximum performance and code size, we will
15NOT guarantee API/ABI stability for Java Lite. If this is not acceptable
16for your use-case, please use the full Java runtime instead. Note that
17the latest version of Java Lite is not compatible with the 3.0.0 version.
18
19You can generate Java Lite code for your .proto files:
20
21    $ protoc --java_out=lite:${OUTPUT_DIR} path/to/your/proto/file
22
23Note that "optimize_for = LITE_RUNTIME" option in proto file is deprecated
24and will not have any effect any more.
25
26Include the generated Java files in your project and add a dependency on the
27protobuf Java runtime. If you are using Maven, use the following:
28
29```xml
30<dependency>
31  <groupId>com.google.protobuf</groupId>
32  <artifactId>protobuf-javalite</artifactId>
33  <version>3.20.3</version>
34</dependency>
35```
36
37## R8 rule to make production app builds work
38
39The Lite runtime internally uses reflection to avoid generating hashCode/equals/(de)serialization methods.
40R8 by default obfuscates the field names, which makes the reflection fail causing exceptions of the form
41`java.lang.RuntimeException: Field {NAME}_ for {CLASS} not found. Known fields are [ {FIELDS} ]` in MessageSchema.java.
42
43There 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).
44
45Until the issues is resolved you need to add the following line to your `proguard-rules.pro` file inside your project:
46
47```
48-keep class * extends com.google.protobuf.GeneratedMessageLite { *; }
49```
50
51## Older versions
52
53For the older version of Java Lite (v3.0.0), please refer to:
54
55    https://github.com/protocolbuffers/protobuf/blob/javalite/java/lite.md
56