Download https://github.com/moritz-wundke/Boost-for-Android
Unzip into the directory
run ./build-android.sh $(NDK_ROOT)
NDK_ROOT ndk-build is located in that directory
Then will automatically download the source code to compile, NDK r19 above will automatically select the c ++ _ shared runtime library, will download version 1.70, and then generate multiple ABI libraries
To select a different run-time libraries, and so need to be amendedbuild-android.sh???具体不会
After generating Android studio use, the following configuration cmake
########## ######### added boost library the begin # does not exist because it is manually configured findboost.cmake can use available after after # $ {Boost_INCLUDE_DIR} and $ {Boost_LIBRARIES} the # SET (Boost_ADDITIONAL_VERSIONS " 1.70 " ) SET (the BOOST_ROOT / Home / HK / the Android / Boost / $ {} ANDROID_ABI) SET (Boost_INCLUDE_DIR the BOOST_ROOT {$} / the include / Boost- 1_70) SET (Boost_LIBRARY_DIR the BOOST_ROOT} {$ / lib) # wildcard add multiple dependent lib library file (GLOB Boost_LIBRARIES " $ {} /libboost*.a Boost_LIBRARY_DIR " ) include_directories ($ {} Boost_INCLUDE_DIR) ########## added boost library end ## ####################################
Such links
#链接库 target_link_libraries( native-lib ${Boost_LIBRARIES} )
Test code
//测试boost extern "C" JNIEXPORT jstring JNICALL Java_com_example_myvio_MainActivity_stringFromJNI( JNIEnv *env, jobject /* this */) { std::string hello = "Hello MyVIO"; //boost::dynamic_bitset<> db4(std::string("0100")); //db4.flip();//1011 /*for(int i=0;i<4;i++) if(db4[i]==1) hello=hello+"1"; else hello=hello+"0";*/ boost::dynamic_bitset<> db4(4, BOOST_BINARY(1010)); db4[0] &= 1; db4[1] ^= 1; //注意右边是低位 for(int i=0;i<4;i++) if(db4[i]==1) hello=hello+"1"; else hello=hello+"0"; return env->NewStringUTF(hello.c_str()); }