想学习下android下的epoll,可惜macos是基于unix的,无epoll库支持

那就直接写cpp到真机上运行吧


项目结构如下图所示


项目文件为

android_helloandroid

|-------jni

|-------|-------helloandroid.cpp

|-------|-------Android.mk

|-------build.sh


helloandroid.cpp文件内容为

#include #include int main(int argc, char const *argv[]){printf("%s\n","halo" );return 0;}



Android.mk文件内容为

# Copyright (C) 2009 The Android Open Source Project## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at##      http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.#LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE    := helloandroidLOCAL_SRC_FILES := helloandroid.cppLOCAL_STATIC_LIBRARIES := libcinclude $(BUILD_EXECUTABLE)
* 注意最后一行为BUILD_EXECUTABLE


运行脚本build.sh为

#!/bin/bashexport MODULE_NAME="helloandroid"ndk-buildadb push libs/armeabi/${MODULE_NAME} /data/localecho ""echo "------ run ${MODULE_NAME} -------"echo ""adb shell /data/local/${MODULE_NAME}rm -r libsrm -r objecho ""


注意需要设置环境变量

我设置在了mac的用户文件里

~/.bash_profile

export ANDROID_SDK_ROOT=/programes/android-sdk-macosxexport ANDROID_NDK_ROOT=/programes/android-ndk-r9dexport COCOS2DX_ROOT=//files/cocos2d-2.0-x-2.0.4export NDK_ROOT=/programes/android-ndk-r8c    export ADB_ROOT=/Applications/Android\ Studio.app/sdk/platform-toolsexport PATH=$PATH:$ANDROID_SDK_ROOTexport PATH=$PATH:$ANDROID_NDK_ROOTexport PATH=$PATH:$ADB_ROOT### Your previous /Users/ashqal/.bash_profile file was backed up as /Users/ashqal/.bash_profile.macports-saved_2014-01-14_at_13:20:36### MacPorts Installer addition on 2014-01-14_at_13:20:36: adding an appropriate PATH variable for use with MacPorts.export PATH=/opt/local/bin:/opt/local/sbin:$PATH# Finished adapting your PATH environment variable for use with MacPorts.
这样就可以直接找到adb、ndk-build命令了


最后是打开真机调试模式,插上真机,打开终端,在项目根目录下运行此build.sh



总结下,

思路就是用ndk-bulid工具的BUILD_EXECUTABLE脚本自动生成android可识别的可运行文件,

然后用adb工具把文件上传到真机上,

然后用adb shell命令执行此文件


更多相关文章

  1. android读取properties配置文件
  2. android中The connection to adb is down,问题和解决
  3. Android(安卓)6.0 运行时权限 处理
  4. android studio添加忽略文件
  5. 第100章、WebView应用之Javascript调用Android(从零开始学Android
  6. Android---1---HelloWorld
  7. android调用shell命令及权限问题
  8. android 之使用任意XML资源文件
  9. NPM 和webpack 的基础使用

随机推荐

  1. Android(安卓)生成keystore,两种方式 【包
  2. 关于android avd目录的设置
  3. Linux上添加udev规则使adb可以操作Androi
  4. android实现图片平铺效果&WebView多点触
  5. android studio第一个项目hello world之A
  6. Android(安卓)Studio使用小指南
  7. Android(安卓)File类
  8. Android(安卓)五大布局
  9. Android软键盘弹出,界面整体上移
  10. Android(安卓)Bluetooth源码分析总结 - f