title: How to build lib protobuf along with dynamic library for use in Android application?
body: <p>I'm trying to compile an open source project (let's say <code>foo</code>) into a <code>libfoo.so</code> native library to use for my android app. However, this project also uses google's protocol buffer library.</p>
  
  <p>So i was able to compile Google's lib protobuf for iOS as follows: <a href="https://gist.github.com/BennettSmith/7150245" rel="nofollow">https://gist.github.com/BennettSmith/7150245</a> .</p>
  
  <p>However, this just generates <code>libprotobuf.a</code> file. The problem is that I can't seem to figure out a way to include this <code>libprotobuf.a</code> file to my <code>libfoo.so</code> file for use with my android application. I <em>THOUGHT</em> i had referenced it when i did:</p>
  
  <pre><code>include $(CLEAR_VARS)
  LOCAL_MODULE    := libprotobuf
  LOCAL_SRC_FILES := ./src/lib/libprotobuf.a
  LOCAL_EXPORT_C_INCLUDES := ./src/include
  include $(PREBUILT_STATIC_LIBRARY)
  </code></pre>
  
  <p>in my <code>Android.mk</code> file. However, it seems that it is definitely not getting linked properly. Whenever i try to <code>ndk-build</code> the open source project (which depends on using lib protobuf), i get a bunch of undefined references, like: </p>
  
  <pre><code>undefined reference to 'google::protobuf::internal::empty_string_'
  </code></pre>
  
  <p>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 <code>libfoo.so</code> file, and then somehow link lib protobuf as <code>libprotobuf.a</code> or <code>libprotobuf.so</code> ?? so i ended up using <code>LOCAL_ALLOW_UNDEFINED_SYMBOLS := true</code> to just get my project to generate the <code>libfoo.so</code> file.</p>
  
  <p>but this <code>libfoo.so</code> gives me some load error as soon as i try to use it within my android app:</p>
  
  <pre><code>dlopen failed: cannot locate symbol "_ZN6google8protobuf11MessageLite15ParseFromStringERKSs" referenced by libfoo.so
  </code></pre>
  
  <p>So I'm wondering:</p>
  
  <ul>
  <li>How do i include this protobuf library in my android app?</li>
  <li>Do i try to include this protobuf library into <code>libfoo.so</code> first?</li>
  <li>Would it even work if i tried to ignore linker warnings and then tried to generate <code>libprotobuf.so</code> and include that with my application?</li>
  <li>is it even possible to generate <code>libprotobuf.so</code>? I can't generate it using the instructions on their github - i get a ton of errors</li>
  </ul>
  
  <p>Note that the only reason i'm even able to get <code>undefined reference</code> errors when trying to generate <code>libfoo.so</code> is because i manually copied all of the <code>*.h</code> in google's lib protobuf.</p>
  
  <p>Any help would be greatly appreciated!!!</p>