Empty output if compact fails.

There must be equal number of start/end calls with right token given in
order, if used in wrong order, ProtoOutputStream will have empty output.

Also refactor Android.bp, so the gtest is standalone unit test, it used
to require compile/push libprotoutil.so to device.

Bug: 77342154
Test: atest libprotoutil_test
Change-Id: I0011bbab34c04cb38164d2ed21cd818d52a2ecf9
diff --git a/libs/protoutil/Android.bp b/libs/protoutil/Android.bp
index 14b2e41..44bc97a 100644
--- a/libs/protoutil/Android.bp
+++ b/libs/protoutil/Android.bp
@@ -12,9 +12,8 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
-
-cc_library {
-    name: "libprotoutil",
+cc_defaults {
+    name: "libprotoutil_defaults",
 
     cflags: [
         "-Wall",
@@ -30,8 +29,6 @@
         "src/protobuf.cpp",
     ],
 
-    export_include_dirs: ["include"],
-
     shared_libs: [
         "libbase",
         "libcutils",
@@ -39,15 +36,24 @@
     ],
 }
 
+cc_library {
+    name: "libprotoutil",
+
+    defaults: ["libprotoutil_defaults"],
+
+    export_include_dirs: ["include"],
+}
+
 cc_test {
     name: "libprotoutil_test",
 
+    defaults: ["libprotoutil_defaults"],
+
+    local_include_dirs: ["include"],
+
     srcs: ["tests/*"],
 
     shared_libs: [
-        "libbase",
-        "libcutils",
-        "libprotoutil",
         "libprotobuf-cpp-full",
     ],