Enable Boost C ++ library in android

I tried for a long time to marry Boost and android on the windows and tried many approaches, but still no luck. I want to create a sample program using the Boost library in android. I follow this guide here.

As shown in this tutorial, I saved my Boost lib to **** (Android NDK) \ sources \ boost_1_44_0 ****, compiled it successfully.

Then I created an Android.mk file inside sources / boost_1_44_0 and recorded every library I want to use. In this case, lib. The file libboost_date_time-gcc-mt-s-1_44.a is available in boost_1_44_0 / android / lib /
Here is the contents of the Android.mk file.

LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE:= boost_date LOCAL_SRC_FILES:= boost_1_44_0/android/lib/libboost_date_time-gcc-mt-s-1_44.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) include $(PREBUILT_STATIC_LIBRARY) 

Now the next step is to create the Android.mk file in the project directory, inside the jni folder (this is the creation of a shared library). Here is its content.

 LOCAL_PATH := $(call my-dir) include $(call all-subdir-makefiles) include $(CLEAR_VARS) # Here we give our module name and source file(s) LOCAL_LDLIBS := -llog -ldl LOCAL_MODULE := ndkfoo LOCAL_SRC_FILES := ndkfoo.cpp LOCAL_STATIC_LIBRARIES := boost_date include $(BUILD_SHARED_LIBRARY) $(call import-module,boost_1_44_0) 

Here is the Application.mk file located in the same place, inside the jni folder. The contents of the Application.mk file are as follows:

 APP_STL = gnustl_static #(or APP_STL = stlport_static as required) APP_CPPFLAGS = -fexceptions 

And finally, here is my ndkfoo.cpp file

 #include <string.h> #include <jni.h> #include <stdio.h> #include <boost/date_time.hpp> using namespace boost::gregorian; void Java_com_ndkfoo_NdkfooActivity_invokeNativeFunction(JNIEnv* env, jobject javaThis) { date weekstart(2002,Feb,1); } 

this program may be incorrect, but the problem is that it does not recognize headers or enhancement functions. and I always get a compilation error.

Is there something I don't see or am doing wrong? Any help could be helpful.

EDIT: This question contains everything you need to enable the Boost library in android. See my answer below for more information. Hope this also works for you.

Thank.

+21
c ++ android boost jni
Oct 25 '11 at 6:18
source share
1 answer

My question had almost complete steps to enable the BOOST library in android. But still there are some important points that you should remember when working with this.

  • Delete the automatically generated obj and lib folder Each time before compiling your own code.

  • If you are going to write your own C ++ code, add LOCAL_CPP_EXTENSION := .cpp to your Android.mk file ( jni/Android.mk ).

  • if you are going to write C ++ code, put all the cpp code inside extern "C" {} .

    extern C { /*cpp code*/ }

  • Do not give up, be patient and keep trying .;).

+5
Dec 12 '11 at 5:18
source share



All Articles