How do I run a compiled binary in Android? How do I run a compiled binary in Android? shell shell

How do I run a compiled binary in Android?


Your binary apparently depends on some shared library (.so) that is not visible for dynamic linking. You can use readelf from your toolchain and you get something like this:

tom@pc:~/workspace/test/arm-v7a_android9/release$ ~/toolchains/armeabiv7a_android-9_ndk-r10e_gcc-4.9/bin/arm-linux-androideabi-readelf -d testDynamic section at offset 0x445a14 contains 27 entries:  Tag        Type                         Name/Value 0x00000003 (PLTGOT)                     0x44fc50 0x00000002 (PLTRELSZ)                   1864 (bytes) 0x00000017 (JMPREL)                     0x74d24 0x00000014 (PLTREL)                     REL 0x00000011 (REL)                        0x74cd4 0x00000012 (RELSZ)                      80 (bytes) 0x00000013 (RELENT)                     8 (bytes) 0x00000015 (DEBUG)                      0x0 0x00000006 (SYMTAB)                     0x8148 0x0000000b (SYMENT)                     16 (bytes) 0x00000005 (STRTAB)                     0x26718 0x0000000a (STRSZ)                      273460 (bytes) 0x00000004 (HASH)                       0x6934c 0x00000001 (NEEDED)                     Shared library: [liblog.so] 0x00000001 (NEEDED)                     Shared library: [libm.so] 0x00000001 (NEEDED)                     Shared library: [libc.so] 0x00000001 (NEEDED)                     Shared library: [libdl.so] 0x0000001a (FINI_ARRAY)                 0x447cb8 0x0000001c (FINI_ARRAYSZ)               12 (bytes) 0x00000019 (INIT_ARRAY)                 0x447cc4 0x0000001b (INIT_ARRAYSZ)               324 (bytes) 0x00000020 (PREINIT_ARRAY)              0x447e08 0x00000021 (PREINIT_ARRAYSZ)            0x8 0x0000001e (FLAGS)                      BIND_NOW 0x6ffffffb (FLAGS_1)                    Flags: NOW 0x00000000 (NULL)                       0x0

Check that all libraries with type (NEEDED) are on your Android device and are visible for your binary (you should use export LD_LIBRARY_PATH=<path>[:<another_path>[..]] to make .so available for dynamic linking with your binary).

If problem isn't still resolved, your application is linked with different version of some system library - try to use an older toolchain.


Did you try the methods in this thread?"No such file or directory" trying to execute linux binary on Android device

An alternative way to solve this problem would be installing KBOX on Android. The author has developed tools like gcc, ssh server for the Android platform. Therefore, you can start an ssh server on your phone and do all your work on your PC, which means that you can compile your code directly on the phone :)