No such file or directory error when executing a binary
The answer is in this line of the output of readelf -a
in the original question
[Requesting program interpreter: /lib/ld-linux.so.2]
I was missing the /lib/ld-linux.so.2 file, which is needed to run 32-bit apps. The Ubuntu package that has this file is libc6-i386.
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 test
Dynamic 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.
Android: cannot execute file compiled through Linux Deploy on the same phone
You should compile your binary with gcc '-static' key. If you don't do that, you binary will need dynamic linker ld.so that doesn't exist on Android (but definitely exists inside your chroot!). This implies that strange error message "No such file or directory".
Android shell don't find the file to execute
Your executable is missing a library. The most likely reason is that you just built a Linux ARM executable (not an Android one) which is linked against some libc
version other than Android Bionic.
You could either learn how to build proper Android executables or a statically linked binary might just work for your purpose.
Installing a prebuilt binary on Android: not found
Perhaps some of the required dynamic libraries can't be found.
Try 'ldd binary_name'
The output should look a little like this if all libraries can be found.
Missing libraries should be clearly marked.
linux-gate.so.1 => (0xb7fbf000)
libcap.so.2 => /lib/libcap.so.2 (0xb7fa7000)
libdl.so.2 => /lib/i686/cmov/libdl.so.2 (0xb7fa3000)
libncursesw.so.5 => /lib/libncursesw.so.5 (0xb7f64000)
libm.so.6 => /lib/i686/cmov/libm.so.6 (0xb7f3e000)
libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb7dde000)
libattr.so.1 => /lib/libattr.so.1 (0xb7dd9000)
/lib/ld-linux.so.2 (0xb7fc0000)
No such file or directory while running dalvikvm
I copied the ls program (from bin directory of device) in /opt, it executes fine-
root@localhost:/opt# file ls
ls: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux
2.6.16, BuildID[sha1]=0xd9839725f151e64cfbf15a463e605227938a1619, not stripped
root@localhost:/opt# ./ls
dalvikvm data dbspace etc ls share usr var
One question is the file command output shows executable in case of ls command, but it shows shared object in case of dalvikvm or any other binary I copy from my AOSP build.
Why is dalvikvm not showing as executable?
Related Topics
How to Change the Color of Header Bar and Address Bar in Newest Chrome Version on Lollipop
Facebook Key Hash Does Not Match Any Stored Key Hashes
Using the Recyclerview with a Database
Embedding Ads Within Recyclerview
How to Pass Drawable Between Activities
How to Create Standard Borderless Buttons (Like in the Design Guideline Mentioned)
Android Textview Padding Between Lines
How to Save a Bitmap on Internal Storage
Android: How to Detect Double-Tap
Android Webview Err_Unknown_Url_Scheme
How to Set Margin of Imageview Using Code, Not Xml
Android Get Image from Gallery into Imageview
What Is "Android.R.Layout.Simple_List_Item_1"
Locationsettingsrequest Dialog to Enable Gps - Onactivityresult() Skipped
Searchview in Listview Having a Custom Adapter
How to Show a Dialog to Confirm That the User Wishes to Exit an Android Activity