Termux permission denied - android

I want to execute a simple code in Termux(c++) but every time I get an error:
bash: ./test.cpp: Permission denied
Storage permission is on and gcc is installed.
Do I need root or something else?

As molbdnilo said, you should compile your source file first :
g++ test.cpp
And then execute the binary produced (the default name is a.out)
./a.out

Compile and run it in termux's own directory.
Just start termux:
cd storage/
nano test.cpp
g++ test.cpp "./a.out"
You can run it!

C++ can't do it,you must compile first.
And if it Python,you can add #!/usr/bin/env python to first line,and in shell run chmod 744 xxx.py,and then run ./xxx.py.xxx.py is running.

I never used termux but would Like to suggest U following points for compiling
use chmod 777 test.cpp to grant the permission for read write and execute to all users
use g++ along with gcc to compile C++ files
use sudo apt-get update followed by sudo apt-get install g++
compile using g++ test.cpp -o test
and use ./test to execute the file.
This is how it work in Linux systems.

Related

Issues with building Android native executable programs through CMake and arm-linux-gnueabi-gcc

CMakeLists.txt
STRING( REGEX REPLACE ".*/(.*)" "\\1" CURRENT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} )
SET(TARGET ${CURRENT_FOLDER})
PROJECT (${TARGET})
add_compile_options(-static -march=armv7-a)
aux_source_directory(./src SRCS)
add_executable(${TARGET} ${SRCS})
hello.c
#include <stdio.h>
int main(void)
{
printf("hello ARM!!!");
return 0;
}
adb push '.\Desktop\hello' /data/local/tmp
adb shell chmod 777 /data/local/tmp/hello
adb shell /data/local/tmp/hello
/system/bin/sh: /data/local/tmp/hello: No such file or directory
adb shell ls -l /data/local/tmp/
-rwxrwxrwx root root 10652 2021-01-21 17:03 hello
When I compile by the following command
arm-linux-gnueabi-gcc -static -march=armv7-a hello.c -o hello
adb push '.\Desktop\hello' /data/local/tmp
adb shell chmod 777 /data/local/tmp/hello
adb shell /data/local/tmp/hello
hello ARM!!!
I found that the compile_commands.json generated by cmake is
"command": "/bin/arm-linux-gnueabi-gcc-8 -g -static -march=armv7-a -o CMakeFiles/hello.dir/src/hello.c.o -c /home/dev/workspace/ASM/Projects/hello/src/hello.c",
I don't know how to solve this problem.
CMake use two steps to generate executable. The first step it compiles the source files ( c or c++) to object file. then it links the file needed to generate the executable(s).
The compile_commands.json will contain only the commands used to compile and not to link. normally you can find the command used to link in link.txt. this file can be found in CMakeFiles/<name>.dir/link.txt.
You can also , directly run your make commad with VERBOSE=1 to see the executed command on live.
For your problem, i think there is a problem with your TARGET variable, but without more information i can not be sure.

How to compile clk, the Android bootloader?

https://github.com/n0d3/lk – this is the repository holding source code for clk 1.5, which is a bootloader for Android and which I am trying to compile. Compiled packages can be found; however, I need to customize it. How can I compile it?
Running make returns the following:
$ make
makefile:22: *** No project specified. Use "make projectname" or put "PROJECT := projectname" in local.mk. Stop.
Running make htcleo returns the following:
$ make htcleo
make[1]: Entering directory '/cygdrive/c/Users/Domas/lk'
make[1]: arm-eabi-gcc: Command not found
LIBGCC =
CFLAGS = -O2 -g -fno-builtin -finline -W -Wall -Wno-multichar -Wno-unused-parameter -Wno-unused-function -include ./build-htcleo/config.h -ffunction-sections -fdata-sections -mlittle-endian -mfpu=neon -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -mthumb-interwork -mthumb -D__thumb__
including app/aboot dev/battery dev/fbcon dev/keys lib/debug lib/devinfo lib/heap lib/libc lib/ptable
generating build-htcleo/config.h
compiling arch/arm/start.S
make[1]: arm-eabi-gcc: Command not found
arch/arm/compile.mk:30: recipe for target 'build-htcleo/arch/arm/start.o' failed
make[1]: *** [build-htcleo/arch/arm/start.o] Error 127
make[1]: Leaving directory '/cygdrive/c/Users/Domas/lk'
makefile:15: recipe for target 'make-make' failed
make: *** [make-make] Error 2
As you can see the make breaks on make[1]: arm-eabi-gcc: Command not found. I was able to compile an older version (which had a different compilation process) by using a CodeSourcery toolchain, which has arm-none-eabi-gcc.exe, but not arm-eabi-gcc.exe, which seems to be needed to compile this version.
Note:
I appreciate that this might not be a popular type of question here on SO; however, I've been banging my head on this one the whole day, and could really use some guidance.
I managed to compile it. What I did was find a git repository that had a compilation script and some additional files for compilation along side the source code, but it was the old source code. So I downloaded this project, and replaced the source code with a recent one, and the compilation script worked. Below instructions, most of it is copy paste from xda forums:
Download this zip archive here: https://github.com/cedesmith/cLK/archive/master.zip
It's the old source code, but it has the necessary scripts to make compilation easy.
Unzip the archive so that the compile script's path is ~/cLK/compile
Delete the ~/cLK/lk subdirectory (this is the old source code).
Download the new source code: git clone https://github.com/n0d3/lk
Now you should have the new source code in ~/cLK/lk. On to the actual compilation: this will depend on whether you're on Linux or Windows:
Linux
on Debian:
sudo apt-get update
sudo apt-get install gcc make git wget unzip zip libc6-dev-amd64 libc6-dev
on Fedora:
yum install gcc make git wget unzip zip
Now download the CodeSourcery toolchain:
wget http://www.codesourcery.com/sgpp/lite/arm/portal/package5353/public/arm-none-eabi/arm-2009q3-68-arm-none-eabi-i686-pc-linux-gnu.tar.bz2
tar xvfj arm-2009q3-68-arm-none-eabi-i686-pc-linux-gnu.tar.bz2
export PATH=$HOME/clk/arm-2009q3/bin:$PATH
Finally, compile:
cd ~/cLK
./compile clean
If everything goes well, you'll find the RUU_signed in this folder: bin/RUU_signed.nbh
Windows
You'll need Cygwin:
Download, the following file, and execute it http://www.cygwin.com/setup.exe
Click Next
Click "Install from internet" and click Next
Click Next (to accept the default directory to install)
Click Next (to accept the default directory for local Package directory)
Click "Direct Connection", and click Next
Select a "local mirror", and click Next
Now in the search bar, you need to search for the following things to install
gcc
make
git
wget
zip
unzip
Once selected click Next to continue, and Finish
Fire up the cygwin terminal (mintty); the following commands probably don't work in cmd.exe.
Now download CodeSourcery toolchain and yang:
wget http://www.codesourcery.com/sgpp/lite/arm/portal/package5354/public/arm-none-eabi/arm-2009q3-68-arm-none-eabi-i686-mingw32.tar.bz2
tar xvfj arm-2009q3-68-arm-none-eabi-i686-mingw32.tar.bz2
wget http://htc-flasher.googlecode.com/files/yang-1.1_win32.zip
cd cLK/bin
rm -rf yang
mkdir yang
unzip ../../yang-1.1_win32.zip yang/yang.exe
mv yang/yang.exe .
cd ..
sed -i s/yang/yang.exe/g compile
And finally, compile:
export PATH=$HOME/arm-2009q3/bin:$PATH
cd ~/cLK
./compile clean
Now your RUU_signed.nbh will be located in the following folder bin/RUU_signed.nbh

Build script for Android NDK in linux

How can I build my source for android with NDK.
Already I download ndk and I don't know how can I set arch compiler path.
This is my "build-for-android.sh" code:
#!/bin/sh
cairo=system
curl=system
pal=android
alsa=no
pulse=no
sles=yes
ffmpeg=yes
gallium=no
egl=yes
glx=no
PKG_CONFIG_PATH=$MOONLIGHT_PREFIX/lib/pkgconfig
if [ -d /usr/X11/share/aclocal ]; then
export ACLOCAL_FLAGS="-I /usr/X11/share/aclocal"
fi
./autogen.sh --host=arm-linux-androideabi --prefix=$MOONLIGHT_PREFIX --with-manual-mono=yes --with-testing=no --enable-browser-support --disable-desktop-support --with-unwind=no --with-ffmpeg=$ffmpeg --with-alsa=$alsa --with-pulseaudio=$pulse --with-opensles=$sles --with-pal=$pal --with-curl=$curl --with-cairo=$cairo --with-gallium-path=$gallium --enable-sdk=no --with-egl=$egl --with-glx=$glx CFLAGS="-DPLATFORM_ANDROID -I$MOONLIGHT_PREFIX/include $CFLAGS" LDFLAGS="-L$MOONLIGHT_PREFIX/lib $LDFLAGS" CXXFLAGS="-fno-rtti -DPLATFORM_ANDROID -I$MOONLIGHT_PREFIX/include $CFLAGS"
make $#
when I run it I get error below:
checking for arm-linu-androideabi-g++... no
checking for arm-linu-androideabi-c++... no
checking for arm-linu-androideabi-gpp... no
checking for arm-linu-androideabi-aCC... no
checking for arm-linu-androideabi-cc... no
.
.
.
.
I can see them in ~/Android/android-ndk-r8b/toolchains/arm-linux-androideabi-4.4.3/prebuild/linux-x86/bin/* directory.
OK. I found it.:
First, a standalone toolchain is created to make the configure script easier to use
~$ android-ndk-r5b/build/tools/make-standalone-toolchain.sh --platform=android-8 --install-dir=android-8-toolchain
Next, the toolchain's bin directory is added to the PATH.
~$ export PATH=$PATH:~/android-8-toolchain/bin/

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.

Android debugging ndk : permission denied

I am developing a 3D App as a native C++ program.
Doing on Eclipse IDE:
* Started the Android application
* launched GDB server on the device
* launched GDB client
Error starting process.
Cannot run program
/app3D/obj/local/armeabi/app_process
: java.io.IOException: error=13, Permission denied
Then, I have changed the permission:
chmod -R 777 /opt/android/android-ndk-r7
chmod -R 777 /home/project/app3D
But the same error persist.
Has someone experienced a similar issue?
That's weird, the executable is normally located in the libs/armeabi folder, not the obj folder...
Editing the build_binary.mk at \android-ndk\build\core\build-binary.mk got rid of this error:
# $(hide) $(call cmd-strip, $(PRIVATE_DST))
ifneq ($(APP_OPTIM),debug)
$(hide) $(call cmd-strip, $(PRIVATE_DST))
endif
And also added to command the following paramenter:
ndk-build NDK_DEBUG=1
Now it works.

Categories

Resources