39

Q1) I want to run a simple c program on android emulator.I am using windows xp os on my machine. I have installed sdk, jdk, eclipse for android development and succeeded running android application on AVD.

Q2) I just need to know is there any way to run a C program(without any java) on AVD. On my machine I have installed arm and using that I have compiled a C program.

Q3) I also want to know is it possible to push the compiled binary into android device or AVD and run using the terminal of the android device or AVD?

3 Answers 3

23

You can compile your C programs with an ARM cross-compiler:

arm-linux-gnueabi-gcc -static -march=armv7-a test.c -o test 

Then you can push your compiled binary file to somewhere (don't push it in to the SD card):

adb push test /data/local/tmp/test 
Sign up to request clarification or add additional context in comments.

7 Comments

I got Fatal: Kernel too old. Segmentation fault. My ubuntu has kernel 3.2.0-38 while Android usually runs on 2.6.xx Do you know how to force the compiler to statically link the binary with an older glibc?
@TranSonHai: you should use Android NDK and its bionic runtime library instead of the ubuntu tooolchain.
-march=armv7 should be changed to -march=armv7-a.
What about other architectures, such as Intel CPUs ?
you should use android ndk toolchain and find the correct compiler for your architecture: developer.android.com/ndk/guides/standalone_toolchain.html
|
9

if you have installed NDK succesfully then start with it sample application

http://developer.android.com/sdk/ndk/overview.html#samples

if you are interested another ways of this then may this will help

http://shareprogrammingtips.blogspot.com/2018/07/cross-compile-cc-based-programs-and-run.html

I also want to know is it possible to push the compiled binary into android device or AVD and run using the terminal of the android device or AVD?

here you can see NestedVM

NestedVM provides binary translation for Java Bytecode. This is done by having GCC compile to a MIPS binary which is then translated to a Java class file. Hence any application written in C, C++, Fortran, or any other language supported by GCC can be run in 100% pure Java with no source changes.


Example: Cross compile Hello world C program and run it on android

Comments

5

You need to download the Native Development Kit.

2 Comments

I have done it already..but I haven't found anything useful what to do next?
@user1125898 - What do you mean you haven't found anything useful? The NDK is exactly for the purpose of writing native code in C/C++. Scroll to the bottom of the link I provided and you'll see a section on getting started, as well as a link to the NDK discussion group.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.