generated for each enum, and every integer parameter and return value in the generated code meant for this enum will be annotated with it. This interface is generated with the same name and at the same place as the enum members' container interfaces described above under 'enum_style=java', regardless of the enum_style option used. When this is combined with enum_style=java, the interface will be both the '' annotation and the container of the enum members; otherwise the interface has an empty body.
Your app must declare a compile-time dependency on the android-support-annotations library.
For more information on how these annotations help with compile-time type safety, see: https://sites.google.com/a/android.com/tools/tech-docs/support-annotations and https://developer.android.com/reference/android/support/annotation/IntDef.html
To use nano protobufs within the Android repo:
- Set 'LOCAL_PROTOC_OPTIMIZE_TYPE := nano' in your local .mk file. When building a Java library or an app (package) target, the build system will add the Java nano runtime library to the LOCAL_STATIC_JAVA_LIBRARIES variable, so you don't need to.
- Set 'LOCAL_PROTO_JAVA_OUTPUT_PARAMS := ...' in your local .mk file for any command-line options you need. Use commas to join multiple options. In the nano flavor only, whitespace surrounding the option names and values are ignored, so you can use backslash-newline or '+=' to structure your make files nicely.
- The options will be applied to all proto files in LOCAL_SRC_FILES when you build a Java library or package. In case different options are needed for different proto files, build separate Java libraries and reference them in your main target. Note: you should make sure that, for each separate target, all proto files imported from any proto file in LOCAL_SRC_FILES are included in LOCAL_SRC_FILES. This is because the generator has to assume that the imported files are built using the same options, and will generate code that reference the fields and enums from the imported files using the same code style.
- Hint: 'include ' resets all LOCAL_ variables, including the two above.
To use nano protobufs outside of Android repo:
- Link with the generated jar file <protobuf-root>java/target/protobuf-java-2.3.0-nano.jar.
- Invoke with –javanano_out, e.g.:
./protoc '--javanano_out=\
java_package=src/proto/simple-data.proto|my_package,\
java_outer_classname=src/proto/simple-data.proto|OuterName\
:.' src/proto/simple-data.proto
Contributing to nano:
Please add/edit tests in NanoTest.java.
Please run the following steps to test:
- cd external/protobuf
- ./configure
- Run "make -j12 check" and verify all tests pass.
- cd java
- Run "mvn test" and verify all tests pass.
- cd ../../..
- . build/envsetup.sh
- lunch 1
- "make -j12 aprotoc libprotobuf-java-2.3.0-nano aprotoc-test-nano-params NanoAndroidTest" and check for build errors.
- Plug in an Android device or start an emulator.
- adb install -r out/target/product/generic/data/app/NanoAndroidTest.apk
- Run: "adb shell am instrument -w com.google.protobuf.nano.test/android.test.InstrumentationTestRunner" and verify all tests pass.
- repo sync -c -j256
- "make -j12" and check for build errors
Usage
The complete documentation for Protocol Buffers is available via the web at:
https://developers.google.com/protocol-buffers/