我怎样才能运行C二进制文件(可执行文件)的机器人由机器人外壳 [英] How can i run C binary (executable file) in Android from Android Shell

查看:232
本文介绍了我怎样才能运行C二进制文件(可执行文件)的机器人由机器人外壳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我安装的Andr​​oid姜饼2.3.4设备 在这里,我要运行在Android设备C可执行文件

I have Device on which i installed Android Gingerbread 2.3.4 Here i want to run C executable file on android device

我能够运行在设备的Andr​​oid NDK应用程序及其运行完美 但我想只运行一个的hello.c 设备上的可执行文件。

I am able to run android NDK application on Device and its run perfect But i want to run only one hello.c executable file on Device.

/* #includes #defines ... */

int main(){
    // Do something when this is executed
    return 0;
}

有什么办法来编译这个文件,的Andr​​oid NDK 工具链,我们可以运行此文件的可执行

Is there any way to compile this file with Android NDK tool chain and we can run this file's executable

我发现一件事情这里但这不是我使用我的工作的Andr​​oid NDK,修订7B 的Linux 没有目录结构像这样

I found one thing here but this is not working for me i am using Android NDK, Revision 7b of linux There is no directory structure like this

推荐答案

首先,让我说,我的回答是取决于你使用NDK R7B(它会工作R7C也一样)在Linux(其他城市的路径适当其他系统)。

First, let me say that my answer is dependent on your using NDK r7b (it'll work for r7c as well) on Linux (change paths appropriately for other systems).

编辑:最后测试了 NDK R8E 上的的Linux 的Nexus 4 亚洲开发银行 SDK平台工具启18 上的 Windows 7的的(最新为2013年7月25日)的没有root访问权限

Last tested with NDK r8e on Linux and Nexus 4 with adb from SDK Platform-Tools Rev 18 on Windows 7 (latest as of 2013-07-25) without root access.

  1. $ NDK_ROOT (NDK拉链的顶层文件夹解压时)。
  2. 复制 $ NDK_ROOT /样本/ HELLO-JNI 目录 $ NDK_ROOT /来源/你好世界
  3. $ NDK_ROOT /来源/你好世界
  4. 编辑的Andr​​oidManifest.xml 来为应用程序提供一个适当的名称(这是可选)。
  5. $ NDK_ROOT /来源/你好世界/ JNI 。这是源$ C ​​$ c为。
  6. 编辑 HELLO-jni.c ,删除所有code,并把你的的Hello World code。我的是:
  1. Go to $NDK_ROOT (The topmost folder of NDK zip when unzipped).
  2. Copy $NDK_ROOT/samples/hello-jni directory as $NDK_ROOT/sources/hello-world.
  3. Go to $NDK_ROOT/sources/hello-world.
  4. Edit AndroidManifest.xml to give the application an appropriate name (This is optional).
  5. Go to $NDK_ROOT/sources/hello-world/jni. This is where the source code is.
  6. Edit hello-jni.c, remove all the code, and put in your hello world code. Mine is:
#include 
int main( int argc, char* argv[])
{
    printf("Hello, World!");
    return 0;
}

  • 编辑 Android.mk 并更改行包括$(BUILD_SHARED_LIBRARY)包括: $(BUILD_EXECUTABLE)。您还可以修改 LOCAL_MODULE 线,你想为你的可执行文件的名称(默认为 HELLO-JNI
  • 返回 $ NDK_ROOT /来源/你好世界
  • 运行 ../../ NDK建造以创建可执行文件。
  • $ NDK_ROOT /源将其复制/ HELLO-JNI /库/ armeabi / HELLO-JNI /数据/本地/ tmp目录在Android设备上,并改变它的权限为755(rwxr-XR-X)。如果您在 $ NDK_ROOT /源改变了 LOCAL_MODULE 行/你好世界/ JNI / Android.mk ,可执行名字将是 LOCAL_MODULE 的新值,而不是 HELLO-JNI 。 (所有这一切都是通过亚行完成从Android SDK中。)
  • 全路径 /数据/本地的/ tmp / HELLO-JNI ,或随便你把它命名为执行二进制代码。
  • Edit Android.mk and change the line include $(BUILD_SHARED_LIBRARY) to include $(BUILD_EXECUTABLE). You can also change the LOCAL_MODULE line to the name you want for your executable(default is hello-jni)
  • Go back to $NDK_ROOT/sources/hello-world
  • Run ../../ndk-build to create the executable.
  • Copy it from $NDK_ROOT/sources/hello-jni/libs/armeabi/hello-jni to /data/local/tmp on the Android device and change it's permissions to 755 (rwxr-xr-x). If you changed the LOCAL_MODULE line in $NDK_ROOT/sources/hello-world/jni/Android.mk, the executable name will be the new value of LOCAL_MODULE instead of hello-jni. (All this is done via adb from the Android SDK.)
  • Execute the binary with full path as /data/local/tmp/hello-jni, or whatever you named it to.
  • 和你做(免费开始在$ NDK_ROOT /文档的文档,以获得更好的主意要做什么)。

    And you're done( and free to start on the documentation in $NDK_ROOT/docs to get a better idea of what to do).

    这篇关于我怎样才能运行C二进制文件(可执行文件)的机器人由机器人外壳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆