ndk版本:android-ndk-r8d,基於ndk內建samples中的test-libstdc++工程進行修改。
1. 例子工程目錄結構:
test-libstdc++ / jni / Android.mk
test-libstdc++ / jni / Application.mk
test-libstdc++ / jni / test-libstdc++.cpp
2. Android.mk檔案:
# A simple test for the minimal standard C++ library#LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := test-libstlLOCAL_SRC_FILES := test-libstl.cppLOCAL_LDLIBS := -lloginclude $(BUILD_EXECUTABLE)include $(CLEAR_VARS)LOCAL_EXECUTABLE := test-libstl
3. Application.mk內容:
APP_STL := stlport_static
4. test-libstdc++.cpp內容:
#include <iostream>#include <string>#include <vector>using namespace std;int main() {vector<string> contents;for (int i=0; i<5; i++) {contents.push_back(string("vector"));}for (int i=0; i<5; i++) {cout << contents[i] << endl;}cout << "hello, world\n";return 0;}
5. 最後在test-libstdc++\libs\armeabi目錄下面產生test-libstl 可執行程式。原理類似tcpdump工具使用,通過adb推到手機上,在shell模式下運行改可執行程式:
D:\android-sdk-windows\platform-tools>adb push test-libstl /data/local/1341 KB/s (251396 bytes in 0.182s)D:\android-sdk-windows\platform-tools>adb shell chmod 755 /data/local/test-libstlD:\android-sdk-windows\platform-tools>adb shell /data/local/test-libstlvectorvectorvectorvectorvectorhello, world
參考:http://tungchingkai.blogspot.com/2011/08/how-to-build-android-ndk-sample-using.html