Linux下C++ Socket移植到Android

 Linux下C++ Socket编程    源代码-》Linux Socket Programming In C++ By Rob Tougher  网址http://tldp.org/LDP/LG/issue74/tougher.html

博客 http://blog.csdn.net/engrossment/article/details/7821791对其进行简单的翻译,梳理一下重点

1.编写android代码
public native int connect();
    public native int connect();
    static {
        System.loadLibrary("my-jni");
    }
特别注意加访问intent权限
  <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
不加这玩意,最后调试半天还以为代码有误,360也关掉。

2.Android.mk
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
APP_STL := gnu-libstdc++
LOCAL_MODULE    := my-jni
LOCAL_SRC_FILES := my-jni.cpp Socket.cpp ServerSocket.cpp ClientSocket.cpp simple_server_main.cpp simple_client_main.cpp
LOCAL_LDLIBS := -llog
LOCAL_C_INCLUDES := D:\android-ndk-r8d-windows\android-ndk-r8d\sources\cxx-stl\stlport\stlport
LOCAL_CPPFLAGS += -fexceptions
LOCAL_CFLAGS:=-D_STLP_USE_NEWALLOC
include $(BUILD_SHARED_LIBRARY)
还有Application.mk,加入
APP_STL := stlport_static

两者名字不同

3.Include文件引入,eg:D:\android-ndk-r8d-windows\android-ndk-r8d\sources\cxx-stl\stlport\stlport

谢谢两位博主


你可能感兴趣的:(Linux下C++ Socket移植到Android)