How can i run C binary (executable file) in Android from Android Shell

8,795 views
Skip to first unread message

Sam Jona

unread,
Mar 26, 2012, 1:15:07 PM3/26/12
to android-ndk
I have Android-embedded 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 Device and its run perfect
But i want to run only one hello.c executable file on Device directly.

/* #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 and
we can run this file's executable.

I found one thing http://my.opera.com/otaku_2r/blog/build-and-run-c-application-on-android

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

/data/local
# ./hello
/system/bin/sh: ./hello: not found

I also tried this /system/bin/hello but cant able to run this Binary
file.

Thanks. Any help Will be appreciated.

mic _

unread,
Mar 26, 2012, 4:02:02 PM3/26/12
to andro...@googlegroups.com
Did you set the right permissions for the executable? (e.g.   chmod 777 hello)

/Michael 


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


girlCoder

unread,
Mar 26, 2012, 4:04:56 PM3/26/12
to andro...@googlegroups.com
Your phone must be rooted and you need to run your file from the directory you pushed it to.

Ex:  adb push hello /data/local
       adb shell
       cd /data/local
       ./hello

A B

unread,
Mar 26, 2012, 10:27:06 PM3/26/12
to andro...@googlegroups.com
Ya Phone is rooted and i have all permissions

I pushed same manner which u suggested here..


Can u please let me know how android Source code compile his own source files which are written in C?


thanks

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/YrNYWM4z6KEJ.

Chris Stratton

unread,
Mar 26, 2012, 11:00:08 PM3/26/12
to andro...@googlegroups.com
On Monday, March 26, 2012 4:04:56 PM UTC-4, girlCoder wrote:
Your phone must be rooted and you need to run your file from the directory you pushed it to.

Not true.  Running executable is discouraged, but not prevented in stock releases.  Root is not required.

It is also entirely possible to run one from a different directory than the current by specifying the path.

But it's debatable if this is even on topic for the ndk group.

Tengfu Liu

unread,
Jul 1, 2013, 5:12:22 AM7/1/13
to andro...@googlegroups.com
you should compile you bin with -static

Marcus Moran

unread,
Jul 1, 2013, 9:31:08 AM7/1/13
to andro...@googlegroups.com

Here go my steps:

 

1. write a C program testEXE.c and build into an executable file "testEXE".

// testEXE.c

#include <stdio.h>

int main() {

   printf("Hello. Test succeeded.");

}

 

2. On PC, with Android SDK installed, run "cmd" (Command Prompt)

 

cd C:\android-sdk\platform-tools   (my sdk folder is c:\android-sdk)

adb push testEXE /sdcard/

adb shell

cd /data/local

mkdir tmp

cat /sdcard/testEXE > /data/local/tmp/testEXE

cd /data/local/tmp

chmod 751 testEXE

 

3. then, on the android phone, tap to launch the "Android Terminal Emulator"

cd /data/local/tmp

$ ./testEXE


You should be able to see it working now.  




--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.

To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Alex Cohn

unread,
Nov 7, 2013, 5:25:53 AM11/7/13
to andro...@googlegroups.com
See http://stackoverflow.com/questions/17383552/how-to-package-native-commandline-application-in-apk - there I show how you can easily package your native (C) executable file with your APK, so that the usual installer does all heavy lifting for you.

BR,
Alex Cohn
Reply all
Reply to author
Forward
0 new messages