Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use NDK to build Protobuf to run on Android #5279

Closed
LHM69 opened this issue Oct 22, 2018 · 5 comments

Comments

@LHM69
Copy link

commented Oct 22, 2018

Using

  • Ubuntu 16.04
  • Android NDK r16b
  • Protobuf v3.5.1
  • Language C++
  • Qt 5.9.6 on Android

Build Protobuf with Android NDK

refer to Android Standalone Toolchains

~/Android/android-ndk-r16b/build/tools/make-standalone-toolchain.sh \
--arch=arm \
--platform=android-21 \
--toolchain=arm-linux-androideabi-4.9 \
--install-dir=Android/arm-21-toolchain

get protobuf

git clone https://github.com/protocolbuffers/protobuf.git

cd protobuf

git checkout v3.5.1

./autogen.sh

mkdir build && cd build

vi build-protobuf-android.sh

build-protobuf-android.sh content

export NDK_ROOT=~/Android/android-ndk-r16b
export PREFIX=$HOME/Android/protobuf-3.5.1/
export PATH=$HOME/Android/arm-21-toolchain/bin:$PATH
export SYSROOT=$HOME/Android/arm-21-toolchain/sysroot
export CC="arm-linux-androideabi-gcc --sysroot $SYSROOT"
export CXX="arm-linux-androideabi-g++ --sysroot $SYSROOT"
export CXXSTL=$NDK_ROOT/sources/cxx-stl/gnu-libstdc++/4.9

../configure \
--prefix=$PREFIX \
--host=arm-linux-androideabi \
--with-sysroot="${SYSROOT}" \
--enable-shared \
--enable-cross-compile \
--with-protoc=protoc \
CFLAGS="-march=armv7-a -D__ANDROID_API__=21" \
CXXFLAGS="-frtti -fexceptions -march=armv7-a \
-I${NDK_ROOT}/sources/android/support/include \
-I${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.9/include \
-I${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -D__ANDROID_API__=21" \
LDFLAGS="-L${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a" \
LIBS="-llog -lz -lgnustl_static"

make -j2

make install

Build

bash build-protobuf-android.sh

Build Success!

tree $HOME/Android/protobuf-3.5.1/

├── bin
│   └── protoc
├── include
│   └── google/*
└── lib
    ├── libprotobuf.a
    ├── libprotobuf.la
    ├── libprotobuf-lite.a
    ├── libprotobuf-lite.la
    ├── libprotobuf-lite.so
    ├── libprotobuf.so
    ├── libprotoc.a
    ├── libprotoc.la
    ├── libprotoc.so
    └── pkgconfig
        ├── protobuf-lite.pc
        └── protobuf.pc

Using Protobuf in Qt

qt_android_protobuf_test.zip

proto file

syntax = "proto3";
package proto_pack;

message MapInfo{
   string map_name = 1;
   int32 map_index = 2;
}

message MapListResponse{
   repeated string map_name = 1;
}

message MapIndexResponse{
   repeated int32 map_index = 1;
}

message MapInfoResponse{
   repeated MapInfo map_info = 1;
}

Example

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QDebug>
#include <string>
#include "proto/proto_pack.pb.h"

MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  ui(new Ui::MainWindow)
{
  ui->setupUi(this);
}

MainWindow::~MainWindow()
{
  delete ui;
}

void MainWindow::on_pbtn_string_clicked()
{
  // init
  proto_pack::MapListResponse map_list_res;
  std::string *str_res = map_list_res.add_map_name();
  *str_res = "proto-test";
  qDebug() << "++++++++++++ByteSize" << map_list_res.ByteSize();
  qDebug() << "++++++++++++map_name" << QString::fromStdString(map_list_res.map_name(0));

  std::string str_ser;
  // SerializeToString [error]
#if 0
  map_list_res.SerializeToString(&str_ser);
  qDebug() << "++++++++++++str_ser" << QString::fromStdString(str_ser);
#endif

  // SerializeToArray [pass]
  const int byte_size = map_list_res.ByteSize();
  char arry[byte_size];
  map_list_res.SerializeToArray(arry, byte_size);
  str_ser = std::string(arry, byte_size);
  qDebug() << "++++++++++++str_ser" << QString::fromStdString(str_ser);

  // ParseFromString [error]
#if 0
  proto_pack::MapListResponse par_map_list;
  par_map_list.ParseFromString(str_ser);
  qDebug() << "++++++++++++map_name" << QString::fromStdString(par_map_list.map_name(0));
#endif

  // ParseFromArray [error]
  proto_pack::MapListResponse arr_map_list;
  arr_map_list.ParseFromArray(arry, byte_size);
  qDebug() << "++++++++++++map_name" << QString::fromStdString(arr_map_list.map_name(0));
}

void MainWindow::on_pbtn_int_clicked()
{
  // init
  proto_pack::MapIndexResponse map_index_res;
  map_index_res.add_map_index(233);
  qDebug() << "-----------ByteSize" << map_index_res.ByteSize();
  qDebug() << "-----------map_index" << map_index_res.map_index(0);

  std::string str_ser;
  // SerializeToString [error]
#if 0
  map_index_res.SerializeToString(&str_ser);
  qDebug() << "-----------str_ser" << QString::fromStdString(str_ser);
#endif

  // SerializeToArray [pass]
  const int byte_size = map_index_res.ByteSize();
  char arry[byte_size];
  map_index_res.SerializeToArray(arry, byte_size);
  str_ser = std::string(arry, byte_size);
  qDebug() << "-----------str_ser" << QString::fromStdString(str_ser);

  // ParseFromString [pass]
  proto_pack::MapIndexResponse par_map_index;
  par_map_index.ParseFromString(str_ser);
  qDebug() << "-----------map_index" << par_map_index.map_index(0);

  // ParseFromString [pass]
  proto_pack::MapIndexResponse arr_map_index;
  arr_map_index.ParseFromArray(arry, byte_size);
  qDebug() << "-----------map_index" << arr_map_index.map_index(0);
}

void MainWindow::on_pbtn_struct_clicked()
{
  // init
  proto_pack::MapInfoResponse map_info_res;
  proto_pack::MapInfo *map_info = map_info_res.add_map_info();
  map_info->set_map_name("proto-test");
  map_info->set_map_index(233);
  qDebug() << "=========ByteSize" << map_info_res.ByteSize();
  qDebug() << "=========map_name" << QString::fromStdString(map_info_res.map_info(0).map_name());
  qDebug() << "=========map_index" << map_info_res.map_info(0).map_index();

  std::string str_ser;
  // SerializeToString [error]
#if 0
  map_info_res.SerializeToString(&str_ser);
  qDebug() << "=========str_ser" << QString::fromStdString(str_ser);
#endif

  // SerializeToArray [pass]
  const int byte_size = map_info_res.ByteSize();
  char arry[byte_size];
  map_info_res.SerializeToArray(arry, byte_size);
  str_ser = std::string(arry, byte_size);
  qDebug() << "=========str_ser" << QString::fromStdString(str_ser);

  // ParseFromString [pass]
  proto_pack::MapInfoResponse par_map_info;
  par_map_info.ParseFromString(str_ser);
  qDebug() << "=========map_name" << QString::fromStdString(par_map_info.map_info(0).map_name());
  qDebug() << "=========map_index" << par_map_info.map_info(0).map_index();

  // ParseFromArray [pass]
  proto_pack::MapInfoResponse arr_map_info;
  arr_map_info.ParseFromArray(arry, byte_size);
  qDebug() << "=========map_name" << QString::fromStdString(arr_map_info.map_info(0).map_name());
  qDebug() << "=========map_index" << arr_map_info.map_info(0).map_index();
}

Error log

F libc    : Invalid address 0xcf3faa6c passed to free: value not allocated
F libc    : Fatal signal 6 (SIGABRT), code -6 in tid 13681 (QtMainThread)

Slow Log (adb logcat)

10-22 19:08:22.808 13890 13908 D libqt_android_protobuf_test.so: ../qt_android_protobuf_test/mainwindow.cpp:26 (void MainWindow::on_pbtn_string_clicked()): ++++++++++++ByteSize 12
10-22 19:08:22.809 13890 13908 D libqt_android_protobuf_test.so: ../qt_android_protobuf_test/mainwindow.cpp:27 (void MainWindow::on_pbtn_string_clicked()): ++++++++++++map_name "proto-test"
10-22 19:08:22.809 13890 13908 D libqt_android_protobuf_test.so: ../qt_android_protobuf_test/mainwindow.cpp:41 (void MainWindow::on_pbtn_string_clicked()): ++++++++++++str_ser "\n\nproto-test"
10-22 19:08:22.809 13890 13908 F libc    : Invalid address 0xcf3f7a6c passed to free: value not allocated
10-22 19:08:22.809 13890 13908 F libc    : Fatal signal 6 (SIGABRT), code -6 in tid 13908 (QtMainThread)
10-22 19:08:22.851 13915 13915 W crash_dump32: type=1400 audit(0.0:181858): avc: denied { search } for name="org.qtproject.example.qt_android_protobuf_test" dev="sda17" ino=6135817 scontext=u:r:crash_dump:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
10-22 19:08:22.861 13915 13915 W crash_dump32: type=1400 audit(0.0:181866): avc: denied { search } for name="org.qtproject.example.qt_android_protobuf_test" dev="sda17" ino=6135817 scontext=u:r:crash_dump:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
10-22 19:08:22.871 13915 13915 W crash_dump32: type=1400 audit(0.0:181867): avc: denied { search } for name="files" dev="sda17" ino=6137586 scontext=u:r:crash_dump:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
10-22 19:08:22.889 13915 13915 I crash_dump32: obtaining output fd from tombstoned
10-22 19:08:22.890   962   962 I /system/bin/tombstoned: received crash request for pid 13890
10-22 19:08:22.892 13915 13915 I crash_dump32: performing dump of process 13890 (target tid = 13908)
10-22 19:08:22.893 13915 13915 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
10-22 19:08:22.893 13915 13915 F DEBUG   : Build fingerprint: 'Xiaomi/sagit/sagit:8.0.0/OPR1.170623.027/V10.0.1.0.OCAMIFH:user/release-keys'
10-22 19:08:22.893 13915 13915 F DEBUG   : Revision: '0'
10-22 19:08:22.893 13915 13915 F DEBUG   : ABI: 'arm'
10-22 19:08:22.893 13915 13915 F DEBUG   : pid: 13890, tid: 13908, name: QtMainThread  >>> org.qtproject.example.qt_android_protobuf_test <<<
10-22 19:08:22.893 13915 13915 F DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
10-22 19:08:22.898 13915 13915 F DEBUG   : Abort message: 'Invalid address 0xcf3f7a6c passed to free: value not allocated'
10-22 19:08:22.898 13915 13915 F DEBUG   :     r0 00000000  r1 00003654  r2 00000006  r3 00000008
10-22 19:08:22.898 13915 13915 F DEBUG   :     r4 00003642  r5 00003654  r6 cdefe678  r7 0000010c
10-22 19:08:22.899 13915 13915 F DEBUG   :     r8 7ffff000  r9 dddddd08  sl cdefe88c  fp cdefe72c
10-22 19:08:22.899 13915 13915 F DEBUG   :     ip 00000000  sp cdefe668  lr ee0a69b7  pc ee0d711c  cpsr 200f0010
10-22 19:08:22.905 13915 13915 F DEBUG   : 
10-22 19:08:22.905 13915 13915 F DEBUG   : backtrace:
10-22 19:08:22.905 13915 13915 F DEBUG   :     #00 pc 0004b11c  /system/lib/libc.so (tgkill+12)
10-22 19:08:22.905 13915 13915 F DEBUG   :     #01 pc 0001a9b3  /system/lib/libc.so (abort+54)
10-22 19:08:22.905 13915 13915 F DEBUG   :     #02 pc 0001efad  /system/lib/libc.so (__libc_fatal+24)
10-22 19:08:22.905 13915 13915 F DEBUG   :     #03 pc 0006bbe7  /system/lib/libc.so (ifree+606)
10-22 19:08:22.905 13915 13915 F DEBUG   :     #04 pc 0006be01  /system/lib/libc.so (je_free+72)
10-22 19:08:22.905 13915 13915 F DEBUG   :     #05 pc 004d9d21  /data/app/org.qtproject.example.qt_android_protobuf_test-o1GShMDp0pmg7sTVuBH65Q==/lib/arm/libprotobuf.so
10-22 19:08:22.905 13915 13915 F DEBUG   :     #06 pc 004d9e47  /data/app/org.qtproject.example.qt_android_protobuf_test-o1GShMDp0pmg7sTVuBH65Q==/lib/arm/libprotobuf.so
10-22 19:08:22.905 13915 13915 F DEBUG   :     #07 pc 0029f3d4  /data/app/org.qtproject.example.qt_android_protobuf_test-o1GShMDp0pmg7sTVuBH65Q==/lib/arm/libprotobuf.so (_ZN6google8protobuf28STLStringResizeUninitializedEPSsj+28)
10-22 19:08:22.905 13915 13915 F DEBUG   :     #08 pc 002a145c  /data/app/org.qtproject.example.qt_android_protobuf_test-o1GShMDp0pmg7sTVuBH65Q==/lib/arm/libprotobuf.so (_ZN6google8protobuf8internal14WireFormatLite9ReadBytesEPNS0_2io16CodedInputStreamEPSs+164)
10-22 19:08:22.905 13915 13915 F DEBUG   :     #09 pc 0001b08c  /data/app/org.qtproject.example.qt_android_protobuf_test-o1GShMDp0pmg7sTVuBH65Q==/lib/arm/libqt_android_protobuf_test.so (_ZN6google8protobuf8internal14WireFormatLite10ReadStringEPNS0_2io16CodedInputStreamEPSs+28)
10-22 19:08:22.905 13915 13915 F DEBUG   :     #10 pc 000167a8  /data/app/org.qtproject.example.qt_android_protobuf_test-o1GShMDp0pmg7sTVuBH65Q==/lib/arm/libqt_android_protobuf_test.so (_ZN10proto_pack15MapListResponse27MergePartialFromCodedStreamEPN6google8protobuf2io16CodedInputStreamE+696)
10-22 19:08:22.905 13915 13915 F DEBUG   :     #11 pc 0029dde8  /data/app/org.qtproject.example.qt_android_protobuf_test-o1GShMDp0pmg7sTVuBH65Q==/lib/arm/libprotobuf.so (_ZN6google8protobuf11MessageLite14ParseFromArrayEPKvi+148)
10-22 19:08:22.905 13915 13915 F DEBUG   :     #12 pc 0001035c  /data/app/org.qtproject.example.qt_android_protobuf_test-o1GShMDp0pmg7sTVuBH65Q==/lib/arm/libqt_android_protobuf_test.so (_ZN10MainWindow22on_pbtn_string_clickedEv+796)
10-22 19:08:22.905 13915 13915 F DEBUG   :     #13 pc 0001e3f0  /data/app/org.qtproject.example.qt_android_protobuf_test-o1GShMDp0pmg7sTVuBH65Q==/lib/arm/libqt_android_protobuf_test.so
10-22 19:08:22.905 13915 13915 F DEBUG   :     #14 pc 0001e588  /data/app/org.qtproject.example.qt_android_protobuf_test-o1GShMDp0pmg7sTVuBH65Q==/lib/arm/libqt_android_protobuf_test.so (_ZN10MainWindow11qt_metacallEN11QMetaObject4CallEiPPv+124)
10-22 19:08:22.905 13915 13915 F DEBUG   :     #15 pc 0013a49d  /data/app/org.qtproject.example.qt_android_protobuf_test-o1GShMDp0pmg7sTVuBH65Q==/lib/arm/libQt5Core.so (_ZN11QMetaObject8activateEP7QObjectiiPPv+1346)
10-22 19:08:22.905 13915 13915 F DEBUG   :     #16 pc 0015f58b  /data/app/org.qtproject.example.qt_android_protobuf_test-o1GShMDp0pmg7sTVuBH65Q==/lib/arm/libQt5Widgets.so (_ZN15QAbstractButton7clickedEb+38)
10-22 19:08:23.359 13915 13915 E crash_dump32: cannot open libmiuindbg.so: No such file or directory
10-22 19:08:23.369   962   962 E /system/bin/tombstoned: Tombstone written to: /data/tombstones//tombstone_09
10-22 19:08:23.372  4804  4918 D PowerKeeper.Event: notifyAMCrash packageName: 0, pid:1561
10-22 19:08:23.374  3293  3345 I octvm_klo: get event file: /data/tombstones/tombstone_09
10-22 19:08:23.375  1561 13916 W ActivityManager:   Force finishing activity org.qtproject.example.qt_android_protobuf_test/org.qtproject.qt5.android.bindings.QtActivity
10-22 19:08:23.375  3293  3345 I octvm_klo: klo lock
10-22 19:08:23.377  3293  3345 I octvm_klo: summary:[signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
10-22 19:08:23.377  3293  3345 I octvm_klo: ]
10-22 19:08:23.377  3293  3345 I octvm_klo: summary: [/system/lib/libc.so (tgkill+12)]
10-22 19:08:23.378  3293  3345 I octvm_klo: summary: [/system/lib/libc.so (abort+54)]
10-22 19:08:23.378  3293  3345 I octvm_klo: summary: [/system/lib/libc.so (__libc_fatal+24)]
10-22 19:08:23.378  3293  3345 I octvm_klo: summary: [/system/lib/libc.so (ifree+606)]
10-22 19:08:23.378  3293  3345 I octvm_klo: summary: [/system/lib/libc.so (je_free+72)]
10-22 19:08:23.378  3293  3345 I octvm_klo: summary: [/data/app/org.qtproject.example.qt_android_protobuf_test-o1GShMDp0pmg7sTVuBH65Q==/lib/arm/libprotobuf.so]
10-22 19:08:23.378  3293  3345 I octvm_klo: summary: [/data/app/org.qtproject.example.qt_android_protobuf_test-o1GShMDp0pmg7sTVuBH65Q==/lib/arm/libprotobuf.so]
10-22 19:08:23.378  3293  3345 I octvm_klo: start gathering logcat log...
10-22 19:08:23.395  1561 13916 D ActivityTrigger: ActivityTrigger activityPauseTrigger 
10-22 19:08:23.412  1561  8926 I OpenGLRenderer: Initialized EGL, version 1.4
10-22 19:08:23.412  1561  8926 D OpenGLRenderer: Swap behavior 2
10-22 19:08:23.469   781   781 E lowmemorykiller: Error writing /proc/13890/oom_score_adj; errno=22
10-22 19:08:23.478  1561  1674 W System.err: java.io.FileNotFoundException: /acct/uid_99056/pid_14561/cgroup.procs (No such file or directory)
10-22 19:08:23.478  1561  1674 W System.err: 	at java.io.FileInputStream.open0(Native Method)
10-22 19:08:23.478  1561  1674 W System.err: 	at java.io.FileInputStream.open(FileInputStream.java:200)
10-22 19:08:23.478  1561  1674 W System.err: 	at java.io.FileInputStream.<init>(FileInputStream.java:150)
10-22 19:08:23.478  1561  1674 W System.err: 	at java.io.FileInputStream.<init>(FileInputStream.java:103)
10-22 19:08:23.478  1561  1674 W System.err: 	at com.miui.server.PerfShielderService.setForkedProcessGroup(PerfShielderService.java:210)
10-22 19:08:23.478  1561  1674 W System.err: 	at com.android.server.am.ExtraActivityManagerService.setForkedProcessGroup(ExtraActivityManagerService.java:1253)
10-22 19:08:23.478  1561  1674 W System.err: 	at com.android.server.am.ActivityManagerServiceInjector.setForkedProcessGroup(ActivityManagerServiceInjector.java:1012)
10-22 19:08:23.478  1561  1674 W System.err: 	at com.android.server.am.ActivityManagerService.applyOomAdjLocked(ActivityManagerService.java:22724)
10-22 19:08:23.478  1561  1674 W System.err: 	at com.android.server.am.ActivityManagerService.updateOomAdjLocked(ActivityManagerService.java:23323)
10-22 19:08:23.478  1561  1674 W System.err: 	at com.android.server.am.BroadcastQueue.processCurBroadcastLocked(BroadcastQueue.java:298)
10-22 19:08:23.478  1561  1674 W System.err: 	at com.android.server.am.BroadcastQueue.processNextBroadcast(BroadcastQueue.java:1379)
10-22 19:08:23.478  1561  1674 W System.err: 	at com.android.server.am.BroadcastQueue.processNextBroadcast(BroadcastQueue.java:850)
10-22 19:08:23.478  1561  1674 W System.err: 	at com.android.server.am.BroadcastQueue$BroadcastHandler.handleMessage(BroadcastQueue.java:175)
10-22 19:08:23.478  1561  1674 W System.err: 	at android.os.Handler.dispatchMessage(Handler.java:105)
10-22 19:08:23.478  1561  1674 W System.err: 	at android.os.Looper.loop(Looper.java:171)
10-22 19:08:23.478  1561  1674 W System.err: 	at android.os.HandlerThread.run(HandlerThread.java:65)
10-22 19:08:23.478  1561  1674 W System.err: 	at com.android.server.ServiceThread.run(ServiceThread.java:46)
10-22 19:08:23.496  3654  3664 I zygote64: Background concurrent copying GC freed 2799(453KB) AllocSpace objects, 15(1896KB) LOS objects, 49% free, 5MB/10MB, paused 387us total 112.119ms
10-22 19:08:23.529  1561 13920 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.bindService:1550 android.content.ContextWrapper.bindService:688 miui.os.DropBoxManager.mm:361 miui.os.DropBoxManager.ml:350 miui.os.DropBoxManager.addText:314 
10-22 19:08:23.543  1561  1561 W Binder  : Outgoing transactions from this process must be FLAG_ONEWAY
10-22 19:08:23.543  1561  1561 W Binder  : java.lang.Throwable
10-22 19:08:23.543  1561  1561 W Binder  : 	at android.os.BinderProxy.transact(Binder.java:741)
10-22 19:08:23.543  1561  1561 W Binder  : 	at com.miui.internal.server.IDropBoxManagerService$Stub$Proxy.add(SourceFile:130)
10-22 19:08:23.543  1561  1561 W Binder  : 	at miui.os.DropBoxManager$2.onServiceConnected(SourceFile:286)
10-22 19:08:23.543  1561  1561 W Binder  : 	at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1645)
10-22 19:08:23.543  1561  1561 W Binder  : 	at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1674)
10-22 19:08:23.543  1561  1561 W Binder  : 	at android.os.Handler.handleCallback(Handler.java:789)
10-22 19:08:23.543  1561  1561 W Binder  : 	at android.os.Handler.dispatchMessage(Handler.java:98)
10-22 19:08:23.543  1561  1561 W Binder  : 	at android.os.Looper.loop(Looper.java:171)
10-22 19:08:23.543  1561  1561 W Binder  : 	at com.android.server.SystemServer.run(SystemServer.java:438)
10-22 19:08:23.543  1561  1561 W Binder  : 	at com.android.server.SystemServer.main(SystemServer.java:275)
10-22 19:08:23.543  1561  1561 W Binder  : 	at java.lang.reflect.Method.invoke(Native Method)
10-22 19:08:23.543  1561  1561 W Binder  : 	at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:246)
10-22 19:08:23.543  1561  1561 W Binder  : 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)
10-22 19:08:23.583  1561  2079 W InputDispatcher: channel '3c4b48a org.qtproject.example.qt_android_protobuf_test/org.qtproject.qt5.android.bindings.QtActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
10-22 19:08:23.583  1561  2079 E InputDispatcher: channel '3c4b48a org.qtproject.example.qt_android_protobuf_test/org.qtproject.qt5.android.bindings.QtActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
10-22 19:08:23.587  1561  2929 W InputDispatcher: Attempted to unregister already unregistered input channel '3c4b48a org.qtproject.example.qt_android_protobuf_test/org.qtproject.qt5.android.bindings.QtActivity (server)'
10-22 19:08:23.587   782  3102 E SurfaceFlinger: Failed to find layer (SurfaceView - org.qtproject.example.qt_android_protobuf_test/org.qtproject.qt5.android.bindings.QtActivity#0) in layer parent (no-parent).
10-22 19:08:23.587   782  3102 E SurfaceFlinger: Failed to find layer (Background for - SurfaceView - org.qtproject.example.qt_android_protobuf_test/org.qtproject.qt5.android.bindings.QtActivity#0) in layer parent (no-parent).
10-22 19:08:23.588  4804  4918 D PowerKeeper.Event: notifyAMProcDied pacakageName: org.qtproject.example.qt_android_protobuf_test, pid:13890
10-22 19:08:23.594   627   627 I Zygote  : Process 13890 exited due to signal (6)
10-22 19:08:23.603  1561  8866 D ActivityTrigger: activityResumeTrigger: The activity in ApplicationInfo{223b355 com.miui.home} is now in focus and seems to be in full-screen mode
10-22 19:08:23.603  1561  8866 E ActivityTrigger: activityResumeTrigger: not whiteListedcom.miui.home/com.miui.home.launcher.Launcher/4050011
10-22 19:08:23.617  1561  1758 W ActivityManager: setHasOverlayUi called on unknown pid: 13890
10-22 19:08:23.618  4612  4723 D GameBoosterService: onGameStatusChange foreground:ForegroundInfo{mForegroundPackageName='com.miui.home', mForegroundUid=10028, mForegroundPid=12115, mLastForegroundPackageName='org.qtproject.example.qt_android_protobuf_test', mLastForegroundUid=10215, mLastForegroundPid=13890, mMultiWindowForegroundPackageName='null', mMultiWindowForegroundUid=-1, mFlags=0}
10-22 19:08:23.624 12115 12786 I RenderThread: RenderThread resumed
10-22 19:08:23.624 12115 12786 D ScreenElementRoot: resume
10-22 19:08:23.624 12115 12786 I NotifierManager: onRegister: miui.maml.NotifierManager$MultiBroadcastNotifier@91fff22
10-22 19:08:23.625 12115 12786 D ScreenElementRoot: resume
10-22 19:08:23.625 12115 12786 D ScreenElementRoot: resume
10-22 19:08:23.636  2724  2724 D StatusBar: disable<e i a s b h r c s q >

issue

How to build the correct Android version of protobuf?
Is there any problem with my use?
help me!
Thanks.

@BSBandme

This comment has been minimized.

Copy link
Contributor

commented Oct 29, 2018

Sorry but I'm not very familiar with c++ build on android. Reassigned to Adam.

@acozzette

This comment has been minimized.

Copy link
Contributor

commented Nov 12, 2018

I don't know for sure but I suspect that there's an ODR violation caused by libqt_android_protobuf_test defining some of the same protobuf symbols that are defined in libprotobuf.

@LHM69

This comment has been minimized.

Copy link
Author

commented Nov 13, 2018

The same way, there is no problem in windows and linux, I guess the possible compilation of the Android version of protobuf is wrong. I don't know where is wrong.

@LHM69

This comment has been minimized.

Copy link
Author

commented Dec 24, 2018

After I compile with clang, this problem no longer appears. I suggest you use clang.

Using

  • Ubuntu 16.04
  • Android NDK r16b
  • Protobuf v3.5.1
  • Language C++
  • Qt 5.12.0 on Android

Build Protobuf with Android NDK

refer to Android Standalone Toolchains

~/Android/android-ndk-r16b/build/tools/make-standalone-toolchain.sh \
--arch=arm \
--platform=android-26 \
--toolchain=arm-linux-android-clang5.0 \
--install-dir=$HOME/Android/arm-26-toolchain-clang \
--use-llvm \
--stl=libc++

get protobuf

git clone https://github.com/protocolbuffers/protobuf.git

cd protobuf

git checkout v3.5.1

./autogen.sh

mkdir build && cd build

vi build-protobuf-android.sh

build-protobuf-android.sh content

export PREFIX=$HOME/Android/andrc/protobuf-3.5.1-v7a/
export PATH=$HOME/Android/arm-26-toolchain-clang/bin:$PATH
export SYSROOT=$HOME/Android/arm-26-toolchain-clang/sysroot
export CC="arm-linux-androideabi-clang --sysroot $SYSROOT"
export CXX="arm-linux-androideabi-clang++ --sysroot $SYSROOT"

../configure \
--prefix=$PREFIX \
--host=arm-linux-androideabi \
--with-sysroot="${SYSROOT}" \
--enable-shared \
--enable-cross-compile \
--with-protoc=protoc \
CFLAGS="-march=armv7-a -D__ANDROID_API__=26" \
CXXFLAGS="-frtti -fexceptions -march=armv7-a -D__ANDROID_API__=26" \
LIBS="-llog -lz -lc++_static"

make -j 2

make install

Build

bash build-protobuf-android.sh

Build Success!

You may need

@LHM69 LHM69 closed this Dec 24, 2018
@RoboEvangelist

This comment has been minimized.

Copy link

commented Apr 18, 2019

After building, how may I transfer the shared libraries to my android phone? Can I just use adb shell to do that, and put the libraries in the /system/lib/ folder inside my phone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.