0

Searching on several projects, I found this line on their android.mk $(call all-proto-files-under, $(src_proto)), and I tried to use this like that:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := my_test
src_proto := $(LOCAL_PATH)/proto

LOCAL_CPP_EXTENSION := .cxx .cpp .cc
LOCAL_CPPFLAGS += -std=c++11

LOCAL_SRC_FILES := main.cc \
                   $(call all-proto-files-under, $(src_proto))

# print the source files
$(warning $(LOCAL_SRC_FILES))

# print only main.cc
$(warning $(LOCAL_SRC_FILES))

LOCAL_C_INCLUDES := $(LOCAL_PATH)/include \
                    $(LOCAL_PATH)/proto

# for logging
LOCAL_LDLIBS    += -llog

# for native asset manager
LOCAL_LDLIBS    += -landroid

include $(BUILD_SHARED_LIBRARY)

But it doesn't work, the warning prints nothing, and the second warning prints only main.cc, the line $(call all-proto-files-under, $(src_proto)) does nothing. I would like to know how can I use protobuf with android ndk.

Alex
  • 3,301
  • 4
  • 29
  • 43

1 Answers1

1

I don't know how to solve it with the all-proto-files-under function specifically, but if you want to add all source files in a directory you can do that in the following way:

PROTOBUF_FILES := $(wildcard $(LOCAL_PATH)/proto/*.cc)
LOCAL_SRC_FILES += $(PROTOBUF_FILES:$(LOCAL_PATH)/%=%)

I suppose you could simplify that into a oneliner if you wanted to. It's also possible to add all source files in all subdirectories under a given directory if you need that:

PROTOBUF_FILES := $(wildcard $(LOCAL_PATH)/proto/**/*.cc)

When I built protobuf myself, I just took the corresponding Android.mk file from the AOSP git and removed all the stuff I didn't need.

Michael
  • 57,169
  • 9
  • 80
  • 125
  • I got build protobuf using a shell script that I found, it generates two lib, a full and a lite, but I can't use the lite, only the full, when I try link with the lite I have link problems, were you able to use the lite? – Alex Dec 30 '14 at 10:16
  • No, because I needed RTTI to be enabled for protobuf in my project, so I built the `libprotobuf-cpp-full-gnustl-rtti` module from the Android.mk file I linked to. – Michael Dec 30 '14 at 10:54