0
votes

I am trying to include static cpp library in android. This library is already compiled(on mac os) and i have its include files.

Here is my Android.mk file

LOCAL_PATH := $(call my-dir)
 include $(call all-subdir-makefiles)
    include $(CLEAR_VARS) 
    LOCAL_MODULE:= utils 
    LOCAL_SRC_FILES:= libUtils.a 
    LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/utils 
    include $(PREBUILT_STATIC_LIBRARY) 

    include $(CLEAR_VARS) 
    LOCAL_MODULE := sample 
    LOCAL_SRC_FILES := sample_cpp.cpp 
    LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) 
    LOCAL_STATIC_LIBRARIES :=  utils
    LOCAL_LDLIBS    := -llog 
    include $(BUILD_SHARED_LIBRARY)

and here is Application.mk file

APP_STL := stlport_static
APP_CPPFLAGS = -fexceptions  

but whenever it try to compile it using NDK i get the error

(Path of file)/libUtils.a: file not recognized: File format not recognized collect2: ld returned 1 exit status

1
can you provide the output of file libUtils.a?plaisthos
sorry but i cant get you? output?N-JOY
Was your library compiled for android? If the library contains code for another type of processor (instruction-set), it won't work!bert-jan
@bert-jan library was compiled with xcode on mac os. and working fine for iphoneN-JOY
You need to compile it for Android using Cygwin for example, have you done that?Donal Rafferty

1 Answers

5
votes

From the comments and so on it sounds like you trying to use a non arm version of the library. You should build the library with the ndk. The documentation has even documentation on how to do that.

For example building sigc++ could be like (from a project of mine, where sigc++ resides in the sigc++ subdirectory)

# SIGC++ Library built as static library
LOCAL_MODULE := sigc
LOCAL_PATH = $(CURRENT_DIR)
LOCAL_CPP_EXTENSION := .cc

LOCAL_SRC_FILES :=    sigc++/signal.cc       sigc++/signal_base.cc  sigc++/trackable.cc 
LOCAL_SRC_FILES +=    sigc++/functors/slot_base.cc  sigc++/adaptors/lambda/lambda.cc 
LOCAL_SRC_FILES += sigc++/connection.cc sigc++/functors/slot.cc

LOCAL_C_INCLUDES := sigc++

include $(BUILD_STATIC_LIBRARY)

But you should really read how the compiling linking works. I am afraid building for android with ndk is more low level than using Xcode or Msvc.