mardi 19 décembre 2017

Android NDK undefined reference to google protobuf

I'm trying to make a shared library that uses protobuf-lite with a native library. I've searched around and I can't find anything related to Android Studio 3, google protobuf-lite, and the Android NDK while using windows. I know someone else has had to have tried to do the same thing I'm doing, but my specifics are not apparent in anything I've read.

I'm running:

  • Windows 10 64-bit
  • Android Studio 3.0.1
  • Android NDK r16
  • protobuf-lite version 3.0.0
  • And targeting armeabi-v7a

I used a DOCKER file to create the libprotobuf-lite.so I'm using. DOCKER FILE:

  FROM debian:stretch

  ENV ANDROID_NDK_HOME /build/android-ndk
  ENV ANDROID_NDK_VERSION=r16

  RUN set -e -x && \
  apt-get update && \
  apt-get install -y \
    unzip \
    wget

  #ADD android-ndk-${ANDROID_NDK_VERSION}-linux-x86_32.zip /build/android-
   ndk.zip
  RUN set -e -x && \
  mkdir /build && \
  cd /build && \
  wget -q http://ift.tt/2fVb5Dn
  ndk-${ANDROID_NDK_VERSION}-linux-x86_32.zip -O android-ndk.zip && \
  unzip -q android-ndk.zip && \
  mv ./android-ndk-${ANDROID_NDK_VERSION} ${ANDROID_NDK_HOME} && \
  rm android-ndk.zip

  #ADD protobuf-cpp-3.0.0.zip /build/protobuf.zip
  RUN set -e -x && \
  cd /build && \
  wget -q 
  http://ift.tt/2D4EAdR
  3.0.0.zip -O protobuf-src.zip && \
  unzip protobuf-src.zip && \
  mv protobuf-3.0.0 protobuf && \
  rm protobuf-src.zip

  RUN set -e -x && \
  cd /build && \
  wget -q 
  http://ift.tt/2oMona1
  linux-x86_32.zip -O protoc.zip && \
  mkdir protoc && \
  cd protoc && \
  unzip ../protoc.zip && \
  cd .. && \
  rm protoc.zip

  RUN set -e -x && \
  apt-get update && \
  apt-get install -y \
    # protobuf compile
    autoconf \
    automake \
    libtool \
    curl \
    make \
    g++ \
    # additional compile not in readme
    libncurses5-dev \
    # make_standalone_toolchain
    python \
    # util
    nano

  RUN /build/android-ndk/build/tools/make_standalone_toolchain.py \
     --arch arm \
     --install-dir /build/android-arm

  ADD build.sh /build
  WORKDIR /build/protobuf


  CMD /bin/bash

I am writing a c++ library to be able to use from the java side. I have an Android.mk file that I'm using in Android Studio to build the native library.

Android.mk File:

    LOCAL_PATH := $(call my-dir)

    include $(CLEAR_VARS)
    LOCAL_MODULE := protobuf-lite
    LOCAL_SRC_FILES := libprotobuf-lite.so
    LOCAL_CFLAGS    := -std=c++11
    include $(PREBUILT_SHARED_LIBRARY)

    include $(CLEAR_VARS)
    LOCAL_MODULE := native-lib
    LOCAL_SRC_FILES := native-lib.cpp \
        BeaconSearchResult.cpp \
        fileformat.pb.cc \
        Geopoint.cpp \
        Location.cpp \
        osmformat.pb.cc \
        osmpbf.cpp \
        OSMPBFread.cpp \
        OSMPOISearch.cpp \
        POI.cpp \
   TARGET_ARCH_ABI := armeabi-v7a
   LOCAL_LDFLAGS := -lz -llog
   LOCAL_SHARED_LIBRARIES := libprotobuf-lite
   LOCAL_CPP_FEATURES := rtti
   LOCAL_CFLAGS    := -std=c++11
   include $(BUILD_SHARED_LIBRARY)

The errors I get are:

  Error:(511) undefined reference to 'google::protobuf::internal::MergeFromFail(char const*, int)'
  Error:(521) undefined reference to 'google::protobuf::internal::ArenaStringPtr::AssignWithDefault(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const*, google::protobuf::internal::ArenaStringPtr)'
  Error:(237) undefined reference to 'google::protobuf::io::LazyStringOutputStream::LazyStringOutputStream(google::protobuf::ResultCallback<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >*>*)'
  Error:(377) undefined reference to 'google::protobuf::io::LazyStringOutputStream::~LazyStringOutputStream()'
  Error:(390) undefined reference to 'google::protobuf::internal::WireFormatLite::WriteString(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::all
  Error:(817) undefined reference to 'google::protobuf::io::CodedOutputStream::VarintSize64(unsigned long long)'
  Error:(830) undefined reference to 'google::protobuf::Arena::AddListNode(void*, void (*)(void*))'
  Error:(640) undefined reference to 'google::protobuf::Arena::AllocateAligned(std::type_info const*, unsigned int)'

And those errors appear in the files:

  • osmformat.pb.cc
  • protobuf/wire_format_lite_inl.h
  • protobuf/arena.h
  • protobuf/generated_message_util.h
  • and fileformat.pb.cc

In total there are 49 errors. I know something I'm doing must be correct because if I take out the line in the Android.mk that is LOCAL_SHARED_LIBRARIES it gives me 159 errors. I'm at my wits end and I could really use some fresh eyes on this. If you need any more information let me know.

Aucun commentaire:

Enregistrer un commentaire