3

I'm trying to compile an open source project (let's say foo) into a libfoo.so native library to use for my android app. However, this project also uses google's protocol buffer library.

So i was able to compile Google's lib protobuf for iOS as follows: https://gist.github.com/BennettSmith/7150245 .

However, this just generates libprotobuf.a file. The problem is that I can't seem to figure out a way to include this libprotobuf.a file to my libfoo.so file for use with my android application. I THOUGHT i had referenced it when i did:

include $(CLEAR_VARS)
LOCAL_MODULE    := libprotobuf
LOCAL_SRC_FILES := ./src/lib/libprotobuf.a
LOCAL_EXPORT_C_INCLUDES := ./src/include
include $(PREBUILT_STATIC_LIBRARY)

in my Android.mk file. However, it seems that it is definitely not getting linked properly. Whenever i try to ndk-build the open source project (which depends on using lib protobuf), i get a bunch of undefined references, like:

undefined reference to 'google::protobuf::internal::empty_string_'

so then i thought that maybe i'm not supposed to have the symbols defined here? like maybe i'm supposed to first compile the libfoo.so file, and then somehow link lib protobuf as libprotobuf.a or libprotobuf.so ?? so i ended up using LOCAL_ALLOW_UNDEFINED_SYMBOLS := true to just get my project to generate the libfoo.so file.

but this libfoo.so gives me some load error as soon as i try to use it within my android app:

dlopen failed: cannot locate symbol "_ZN6google8protobuf11MessageLite15ParseFromStringERKSs" referenced by libfoo.so

So I'm wondering:

  • How do i include this protobuf library in my android app?
  • Do i try to include this protobuf library into libfoo.so first?
  • Would it even work if i tried to ignore linker warnings and then tried to generate libprotobuf.so and include that with my application?
  • is it even possible to generate libprotobuf.so? I can't generate it using the instructions on their github - i get a ton of errors

Note that the only reason i'm even able to get undefined reference errors when trying to generate libfoo.so is because i manually copied all of the *.h in google's lib protobuf.

Any help would be greatly appreciated!!!

David T.
  • 22,301
  • 23
  • 71
  • 123
  • The script you link to looks designed for iOS/OSX. I'm not sure it makes sense for Android. The script appears to pass `--disable-shared` to the `configure` script, which disables building of shared libraries, hence you only get a `.a` file and not `.so`. It also does a lot of other weird-looking things that probably don't make sense on Android. I don't have much experience with Android builds so I can't fully answer the question. – Kenton Varda May 31 '15 at 18:52
  • I tried this: http://stackoverflow.com/questions/7144008/how-to-build-protocol-buffer-by-android-ndk but it is outdated, or just 2.6.1 doesn't work. any ideas? – David T. Jun 01 '15 at 02:01
  • Cross-compiling protobufs should be just like cross-compiling anything else that uses automake/autoconf, except that you have to deal with protoc. (1) compile and install `protoc` on the build machine, (2) `make distclean`, (3) `./configure host=arm-linux-androideabi --with-protoc=protoc`, (4) `make`. – Kenton Varda Jun 01 '15 at 20:37
  • In my tinkering so far, it seems that `libprotobuf.a` does not like to be part of `libstuff.so` .I'm able to build it, but when running it, I am greeted by the message which goes: `libprotobuf FATAL google/protobuf/stubs/common.cc:87] This program was compiled against version 3.0.0 of ...`. I have all correct versions so this error message is salty. Moreover, when i link `libprotobuf.a` to `helloworldapp` it works. So the intermediate dynamic library is what protobuf do not like. I'm still on-going... – daparic Apr 09 '20 at 20:23

0 Answers0