I have a Device on which I installed Android Gingerbread 2.3.4 Here i want to run C executable file on android device
I am able to run android NDK application on this Device and it runs perfect. But I want to run only one hello.c
executable file on the Device.
/* #includes #defines ... */ int main(){ // Do something when this is executed return 0; }
Is there any way to compile this file with Android NDK
tool chain so I can run this file's executable?
I found one thing here but this is not working for me. I am using Android NDK, Revision 7b
for Linux. There is no directory structure like this.
No and no. Pure binary file is just a binary file. You can use include $(BUILD_EXECUTABLE) instead of include $(BUILD_SHARED_LIBRARY) in your Android.mk to build such executable with NDK. is there any way to execute binary from java file(i.e. at run time).
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).
Edit: 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.
Yet Another Edit: Please read this question for altering my instruction for native binaries that need to run on Android 5.0(Lollypop) and later.
$NDK_ROOT
(The topmost folder of NDK zip when unzipped).$NDK_ROOT/samples/hello-jni
directory as $NDK_ROOT/sources/hello-world
.$NDK_ROOT/sources/hello-world
.AndroidManifest.xml
to give the application an appropriate name (This is optional).$NDK_ROOT/sources/hello-world/jni
. This is where the source code is.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
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.And you're done( and free to start on the documentation in $NDK_ROOT/docs to get a better idea of what to do).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With