Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run native ARM executable on Jelly Bean

I am looking for methods to run native ARM executable on Android 4.1 (Jelly Bean). For example, compiling the classical C program

// hello.c
#include <stdio.h>
int main() {
    printf("Hello world");
}

to ARMv7a executable, say hello using the Android NDK and then run it in Android shell. I have tried method suggested on the web such as pushing the executable to /data/local by

adb push hello /data/local

change permission to allow it to be executed by

adb shell chmod 755 /data/local/hello

and then invoke them in the shell using

adb shell /data/local/hello

The last step fails with error:

/data/local/hello: not found

but evidently the file is there. I suspect the problem is that Jelly Bean's shell does not allow one to execute alien binaries anymore. Can anyone confirm this and give me a solution?

like image 225
An Hoa Avatar asked Sep 19 '12 14:09

An Hoa


1 Answers

If you want to run a native ARM binary in Android you have to compile with -static.

The libc that you use to build (if using the standard ARM toolchain and not Android NDK) is different from Android's libc (bionic) and therefore when your binary intends to link dynamically to libc on target it will not because libc doesn't exist on target.

With the -static option you link in what you need from libc at build time and don't have to worry about linking things in dynamically.

like image 91
ericwjr Avatar answered Sep 27 '22 17:09

ericwjr