我怎样才能运行C二进制文件(可执行文件)的机器人由机器人外壳 [英] How can i run C binary (executable file) in Android from Android Shell
问题描述
我有我安装的Android姜饼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
我能够运行在设备的Android 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;
}
有什么办法来编译这个文件,的Android NDK
工具链,我们可以运行此文件的可执行
Is there any way to compile this file with Android NDK
tool chain and we can run this file's executable
我发现一件事情这里但这不是我使用我的工作的Android 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.
- 到
$ NDK_ROOT
(NDK拉链的顶层文件夹解压时)。 - 复制
$ NDK_ROOT /样本/ HELLO-JNI
目录$ NDK_ROOT /来源/你好世界
。 - 到
$ NDK_ROOT /来源/你好世界
。 - 编辑
的AndroidManifest.xml
来为应用程序提供一个适当的名称(这是可选)。 - 到
$ NDK_ROOT /来源/你好世界/ JNI
。这是源$ C $ c为。 - 编辑
HELLO-jni.c
,删除所有code,并把你的的Hello World
code。我的是:
- Go to
$NDK_ROOT
(The topmost folder of NDK zip when unzipped). - Copy
$NDK_ROOT/samples/hello-jni
directory as$NDK_ROOT/sources/hello-world
. - Go to
$NDK_ROOT/sources/hello-world
. - Edit
AndroidManifest.xml
to give the application an appropriate name (This is optional). - Go to
$NDK_ROOT/sources/hello-world/jni
. This is where the source code is. - Edit
hello-jni.c
, remove all the code, and put in yourhello 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
,或随便你把它命名为执行二进制代码。
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
)$NDK_ROOT/sources/hello-world
../../ndk-build
to create the executable.$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.)/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屋!