Android: cannot execute file compiled through Linux Deploy on the same phone - android

root#hammerhead:/data/local # ./HelloWorld
tmp-mksh: ./HelloWorld: No such file or directory
Hello!
I compiled using gcc on Linux Deploy, which as I understand downloads Ubuntu and chroots into the environment. The file runs fine inside of this chroot environment.
As I understand this error is given when the file doesn't match the architecture of the machine. But it is running on the same machine! Does anyone know why this may be happening?
File permissions, ownership and context:
-rwxrwxrwx root root u:object_r:system_data_file:s0 HelloWorld
Id output:
uid=0(root) gid=0(root) context=u:r:init:s0
Using /system/bin/sh
/system/bin/sh: ./Helloworld: No such file or directory
Trying to execute a non existant file:
/system/bin/sh: ./test: not found

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".

Related

Can't compile Chromium for android on Debian 9 - Unable to create file. File name too long

I am trying to compile chromium for android on Debian 9 and I get this error, can someone help me on this?
dacod#phoenix:~/Devel/chromium/src$ ninja -C out/Default cast_shell_apk
ninja: Entering directory `out/Default'
[0/21317] ACTION //third_party/WebKit/Source/bindings/modules/v8:generate...snapshot_external_references(//build/toolchain/android:android_clang_arm)
ninja: error:
WriteFile(__third_party_WebKit_Source_bindings_modules_v8_generate_v8_context_snapshot_external_references___build_toolchain_android_android_clang_arm__rule.rsp):
Unable to create file. File name too long
ninja: build stopped: .
The file system you are building on does not support name sizes long enough to accommodate the 150 character filename:
__third_party_WebKit_Source_bindings_modules_v8_generate_v8_context_snapshot_external_references___build_toolchain_android_android_clang_arm__rule.rsp
Typical file systems will support 255 character file names. Here is a reference:
https://serverfault.com/questions/9546/filename-length-limits-on-linux
However, eCryptfs only supports 143 character file names if it is also configured to encrypt the file names themselves [source]. Are you building in your home folder and is it encrypted? If so, this may be the reason. To check the file name size, run the following in your build folder:
$ getconf NAME_MAX .
143
If it is not 255 you may be building on an ecryptfs partition. Try building in /tmp instead, as it may not be encrypted. You can check this with:
$ getconf NAME_MAX /tmp
255

ADB shell permission issues with python scripts: /data/local/tmp/iperf not found [duplicate]

root#hammerhead:/data/local # ./HelloWorld
tmp-mksh: ./HelloWorld: No such file or directory
Hello!
I compiled using gcc on Linux Deploy, which as I understand downloads Ubuntu and chroots into the environment. The file runs fine inside of this chroot environment.
As I understand this error is given when the file doesn't match the architecture of the machine. But it is running on the same machine! Does anyone know why this may be happening?
File permissions, ownership and context:
-rwxrwxrwx root root u:object_r:system_data_file:s0 HelloWorld
Id output:
uid=0(root) gid=0(root) context=u:r:init:s0
Using /system/bin/sh
/system/bin/sh: ./Helloworld: No such file or directory
Trying to execute a non existant file:
/system/bin/sh: ./test: not found
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".

Unable to compile python for android kivy distribution with pyserial

I am unable to compile a distribution for android when i include pyserial in the python for android build requirements.
I am using the ubuntu kivy vm supplied from the kivy website.
After running the following command:
./distribute.sh -m "pil kivy pyjnius pyserial"
It compiles all the packages except the last one (pyserial) and I get this error:
Installing collected packages: pyserial Running setup.py install for
pyserial
changing mode of build/scripts-2.7/miniterm.py from 664 to 775
changing mode of /tmp/tmp0r9vlU/bin/miniterm.py to 775 Successfully installed pyserial Cleaning up... Exception: Traceback
(most recent call last): File
"/home/kivy/android/python-for-android/build/venv/local/lib/python2.7/site-packages/pip/basecommand.py",
line 122, in main
status = self.run(options, args) File "/home/kivy/android/python-for-android/build/venv/local/lib/python2.7/site-packages/pip/commands/install.py",
line 311, in run
os.path.join(options.target_dir, item) File "/usr/lib/python2.7/shutil.py", line 291, in move
raise Error, "Destination path '%s' already exists" % real_dst Error: Destination path
'/home/kivy/android/python-for-android/build/python-install/lib/python2.7/site-packages/pyserial-2.7-py2.7.egg-info/pyserial-2.7-py2.7.egg-info'
already exists
Storing debug log for failure in /home/kivy/.pip/pip.log
Any help solving this would be appreciated.
I have solved this after a bit of checking the error log.
I will list it here in case someone has the same problem.
The following line:
Error: Destination path
'/home/kivy/android/python-for-android/build/python-install/lib/python2.7/site-packages/pyserial-2.7-py2.7.egg-info/pyserial-2.7-py2.7.egg-info'
already exists
indicates that the directory mentioned should be deleted, but this does not not help. Running the build script after deleting it generates the same error.
The solution was to also delete the directory named "serial" which can also be found in the "site-packages" directory.

cocos2d-2.0-rc2-x-2.0.1 Hello World sample doesn't work using cygwin on windows8

I am unable to build helloWorld sample to get .so to run it in eclipse. I have imported project successfully and changed variable to my root path as required. this is my build_native.sh. I am pasting the only change I made in that file
NDK_ROOT_LOCAL=/cygdrive/e/android-ndk-r8
COCOS2DX_ROOT_LOCAL=/cygdrive/e/cocos2d
And my NDK is working fine because I have executed HelloWorld sample of NDK successfully. My SDK version is 20 and NDK version is 8 and I am using cygwin above than 1.7.. I have executed the chown on my NDK directory.. But when I run the command ./build_native.sh in HelloWorld sample program for cocos2d I get this error
E:/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/arm- linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/png.a: No such file: Permission denied
collect2: ld returned 1 exit status
and when I search for png.a in my NDK directory window can't locate that file. I am confused whether it's a permission error or File isn't there. But I have the latest NDK if file isn't there how come anyone will able to run cocos2d-x??? Need Help!!!
It seems like the permissions on built files were missing when I tried as well.
$ ls -l obj/local/armeabi/png.a
---------- 1 someuser Domain Users 912618 Jul 12 18:23 obj/local/armeabi/png.a
There is a link suggested on the forum which doesn't seem to be accessible right now.
Anyway, to fix, you can set the permission on the files.
$ cd obj/local/armeabi/
$ chmod 664 *.a
$ cd ../../..
Edit: A better fix may be to set the default permissions in /etc/fstab to
none /cygdrive cygdrive binary,noacl,posix=0,user 0 0
Following this, you should be able to run ./build_native.sh.
A command you could use to locate all files below the current directory which have no (read/write) permission available on them is find . -type f -perm 0
See this answer to set write permissions on all files below your working directory.
Consider going through a tutorial on chmod to understand the concept of permissions in linux/unix in case you're unfamiliar with them.

How to compile C into an executable binary file and run it in Android from Android Shell?

I have a 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 this Device and it runs perfect.
But I want to run only one hello.c executable file on the Device.
/* #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 so I can run this file's executable?
I found one thing here but this is not working for me. I am using Android NDK, Revision 7b for Linux.
There is no directory structure like this.
First, let me say that my answer is dependent on your using NDK r7b (it'll work for r7c as well) on Linux (change paths appropriately for other systems).
Edit: Last tested with NDK r8e on Linux and Nexus 4 with adb from SDK Platform-Tools Rev 18 on Windows 7 (latest as of 2013-07-25) without root access.
Yet Another Edit: Please read this question for altering my instruction for native binaries that need to run on Android 5.0(Lollypop) and later.
Go to $NDK_ROOT (The topmost folder of NDK zip when unzipped).
Copy $NDK_ROOT/samples/hello-jni directory as $NDK_ROOT/sources/hello-world.
Go to $NDK_ROOT/sources/hello-world.
Edit AndroidManifest.xml to give the application an appropriate name (This is optional).
Go to $NDK_ROOT/sources/hello-world/jni. This is where the source code is.
Edit hello-jni.c, remove all the code, and put in your hello world code. Mine is:#include
int main( int argc, char* argv[])
{
printf("Hello, World!");
return 0;
}
Edit Android.mk and change the line include $(BUILD_SHARED_LIBRARY) to include $(BUILD_EXECUTABLE). You can also change the LOCAL_MODULE line to the name you want for your executable(default is hello-jni)
Go back to $NDK_ROOT/sources/hello-world
Run ../../ndk-build to create the executable.
Copy it from $NDK_ROOT/sources/hello-jni/libs/armeabi/hello-jni to /data/local/tmp on the Android device and change it's permissions to 755 (rwxr-xr-x). If you changed the LOCAL_MODULE line in $NDK_ROOT/sources/hello-world/jni/Android.mk, the executable name will be the new value of LOCAL_MODULE instead of hello-jni. (All this is done via adb from the Android SDK.)
Execute the binary with full path as /data/local/tmp/hello-jni, or whatever you named it to.
And you're done( and free to start on the documentation in $NDK_ROOT/docs to get a better idea of what to do).
The best/easiest place to put a executable is /data/local. You'll also need to chmod the binary as executable. Often you'll also need to do this in two steps to get the binary from /sdcard/ to /data/local:
$ adb push mybin /sdcard/
$ adb shell
$ cp /sdcard/mybin /data/local/mybin
$ cd /data/local
$ chmod 751 mybin
Caveats:
Not all systems have cp. You can use cat if this is the case:
$ cat /sdcard/mybin > /data/local/mybin
Some systems don't allow write in /data/local for the "shell" user. Try /data/local/tmp
the "/sdcard" location is not executable, meaning that any file there is not executable at all.
the only way to "adb push" executable would be to put them in "/data/local", which should be writable for adb, and allow execution for anyone.
I recently had the same problem on a new nexus-5. I'd like to add that /data/local was not writable by the user ("shell", uid 2000) I got with adb shell. But putting the executable in the subdirectory /data/local/tmp/ worked fine.
In a nutshell,
First, to cross-compile your C code from your host machine, use NDK toolchain with sysroot option and position independent option -fPIE -pie.
$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-gcc \
--sysroot=$NDKROOT/platforms/android-22/arch-arm64 -fPIE -pie main.c -o main
the arch part arrch64 or arch-arm64, the toolchain version part 4.9, platform version part android-22, and the binary format for your host machine darwin-x86_64 may vary by your environment.
Second, push your binary under /data/local/tmp and execute it from adb shell.

Categories

Resources