Genymotion + ndk-build + adb - 编写C++程序,在虚拟机运行
可以以 http://blog.csdn.net/bupt073114/article/details/43114223 示例
虚拟机——D:\Genymobile-virtual-devices\Google Nexus 9 - 5.1.0 - API 22 - 2048x1536
ndk-build——E:\Andriod\android-ndk-r10d
adb.exe——E:\Andriod\android-sdk_r24.3.3-windows\android-sdk-windows\platform-tools
F:\project\android\test\socket\jni 中包含文件:Android.mk, cli.c,serv.c
Android.mk 文件 内容如下:
#------------------------------------------------------
#error: only position independent executables (PIE) are supported.
#PIE这个安全机制从4.1引入,但是Android L之前的系统版本并不会去检验可执行文件是否基于PIE编译出的。
#因此不会报错。但是Android L已经开启验证,如果调用的可执行文件不是基于PIE方式编译的,则无法运行。
# F:\project\android\test\socket\jni
# jni> ndk-build
# jni> ndk-build -B APP_ABI=x86
# F:\project\android\test\socket\libs
# adb push cli /data/data/
# adb push serv /data/data/
# adb shell
# cd /data/data/
# chmod 777 serv
# chmod 777 cli
# ./serv
# ./cli
#------------------------------------------------------
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS += -O3 -fvisibility=hidden
LOCAL_CFLAGS += -pie -fPIE
LOCAL_LDFLAGS += -pie -fPIE
LOCAL_MODULE := serv
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := \
serv.c \
LOCAL_LDLIBS := -lz -llog -L$(SYSROOT)/usr/lib
cmd-strip = $(TOOLCHAIN_PREFIX)strip $1
include $(BUILD_EXECUTABLE)
#include $(BUILD_SHARED_LIBRARY)
#LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS += -O3 -fvisibility=hidden
LOCAL_CFLAGS += -pie -fPIE
LOCAL_LDFLAGS += -pie -fPIE
LOCAL_MODULE := cli
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := \
cli.c \
LOCAL_LDLIBS := -lz -llog -L$(SYSROOT)/usr/lib
cmd-strip = $(TOOLCHAIN_PREFIX)strip $1
include $(BUILD_EXECUTABLE)
#include $(BUILD_SHARED_LIBRARY)
阅读(129) | 评论(0) | 转发(0) |
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
虚拟机——D:\Genymobile-virtual-devices\Google Nexus 9 - 5.1.0 - API 22 - 2048x1536
ndk-build——E:\Andriod\android-ndk-r10d
adb.exe——E:\Andriod\android-sdk_r24.3.3-windows\android-sdk-windows\platform-tools
F:\project\android\test\socket\jni 中包含文件:Android.mk, cli.c,serv.c
Android.mk 文件 内容如下:
#------------------------------------------------------
#error: only position independent executables (PIE) are supported.
#PIE这个安全机制从4.1引入,但是Android L之前的系统版本并不会去检验可执行文件是否基于PIE编译出的。
#因此不会报错。但是Android L已经开启验证,如果调用的可执行文件不是基于PIE方式编译的,则无法运行。
# F:\project\android\test\socket\jni
# jni> ndk-build
# jni> ndk-build -B APP_ABI=x86
adb pull <remote> <local>
adb push <local> <remote>
# F:\project\android\test\socket\libs
# adb push cli /data/data/
# adb push serv /data/data/
# adb shell
# cd /data/data/
# chmod 777 serv
# chmod 777 cli
# ./serv
# ./cli
#------------------------------------------------------
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS += -O3 -fvisibility=hidden
LOCAL_CFLAGS += -pie -fPIE
LOCAL_LDFLAGS += -pie -fPIE
LOCAL_MODULE := serv
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := \
serv.c \
LOCAL_LDLIBS := -lz -llog -L$(SYSROOT)/usr/lib
cmd-strip = $(TOOLCHAIN_PREFIX)strip $1
include $(BUILD_EXECUTABLE)
#include $(BUILD_SHARED_LIBRARY)
#LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS += -O3 -fvisibility=hidden
LOCAL_CFLAGS += -pie -fPIE
LOCAL_LDFLAGS += -pie -fPIE
LOCAL_MODULE := cli
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := \
cli.c \
LOCAL_LDLIBS := -lz -llog -L$(SYSROOT)/usr/lib
cmd-strip = $(TOOLCHAIN_PREFIX)strip $1
include $(BUILD_EXECUTABLE)
#include $(BUILD_SHARED_LIBRARY)
相关热门文章
给主人留下些什么吧!~~
评论热议