Android: Executing a program on adb shell - android

I have created an executable using "include $(BUILD_EXECUTABLE)" command in Android.mk .
My requirement is to execute the above generated executable over the abd shell.
I tried:
Below is my C-Code which is compiled using ndk-build command:
#include <stdio.h>
int main()
{
printf("\n\nHello World\n\n");
return 0;
}
Following is my Android.mk file contents:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := HelloExecutable
LOCAL_SRC_FILES := hello.c
include $(BUILD_EXECUTABLE)
When i execute the command ndk-build the following file is generated:
projectRoot->libs->HelloExecutable
My job is to execute the above generated file on the adb shell. So i first pushed the file onto the sdcard using the following command:
adb push ~/projectRoot->libs->HelloExecutable /sdcard/
Now i switch to adb shell using: $adb shell command(here i'm using an emulator).
Then i change the permissions as: chmod 777 /sdcard/HelloExecutable
Once the above command is executed, i get the executing permissions for my HelloExecutable file.
Then change the current working directory to sdcard. i.e. cd /sdcard/
Now when i try to execute the above file i get the following error:
# ./HelloExecutable
./HelloExecutable: permission denied
To perform the above i'm using an emulator. So can someone please tell the reason for the above error??
I kindly request the viewers to address the above problem. Waiting for your answers. Thanks in advance.

Check if your SD card is mounted with noexec option. Try copying your file to another partition like /data and execute it from there.

Related

Android.mk, Windows Shell: How to get the list of all directories and subdirectories without complete path

LOCAL_PATH := $(call my-dir) //returns jni
LOCAL_C_INCLUDES := jni\shared\Core\filters\supplemental jni\shared\Core\aspect_ratio
jni\shared\Core\cache jni\shared\Core\doc_axis jni\shared\Core\kiss_fft
jni\shared\Core\perspective jni\shared\Core\supplemental jni\shared\Core\types
I have hardcoded the value for LOCAL_C_INCLUDES. However, I'd like to use windows shell command to get this value for LOCAL_C_INCLUDES. I researched on this for over 2 hours but couldn't find any.
How do i get a list of folders and subfolders without the files
Suppress directory names being listed with DIR
ALLFOLDERS := $(shell dir $(LOCAL_PATH)\shared\Core /b /s /ad)
The above command gives me the entire path of directories and subdirectories. However, I require only the path from the current directory i.e jni\shared\Core\filters and not the entire path starting from D:\ etc.

process_begin: CreateProcess(NULL, cp file dir, ...) failed error while building application on eclipse and using cygwin

I am trying to copy header files from source file dir to an include dir from Android.mk. I am building the application in eclipse running on top of windows but using cygwin to generate linux env. I am getting this error
process_begin: CreateProcess(NULL, cp jni/core/source/serialize.h jni/core/include, ...) failed.
Android.mk file looks like:
LOCAL_SRC_FILES := ...
FILE_PATH := $(MY_JNI_DIR)/core/include/
FILE := $(MY_JNI_DIR)/core/source/serialize.h
$(shell cp $(FILE) $(FILE_PATH))
include $(BUILD_STATIC_LIBRARY)
Can anyone tell me what I am doing wrong? Thanks in advance.
Make cannot find "cp.exe".
I solved my problem by adding "${GIT_FOLDER}/usr/bin/" to my path. There was a cp.exe file.

Adding the tests directory to the android build system.img

I need to add the timetest directory's executable to the system.img file so that I can access the command from the shell. The location is at : https://android.googlesource.com/platform/system/extras/+/android-4.4.4_r1/tests/timetest/. So what I did was to go into the timetest directory and issue the following command:
mm snod
The output was as follows:
PRODUCT_COPY_FILES device/generic/goldfish/data/etc/apns-conf.xml:system/etc/apns-conf.xml ignored.
make: Entering directory `/home/username/android_built/android'
target thumb C: timetest <= frameworks/base/cmds/timetest/timetest.c
target StaticExecutable: timetest (out/target/product/hammerhead/obj/EXECUTABLES/timetest_intermediates/LINKED/timetest)
target Symbolic: timetest (out/target/product/hammerhead/symbols/sbin/timetest)
target Strip: timetest (out/target/product/hammerhead/obj/EXECUTABLES/timetest_intermediates/timetest)
Install: out/target/product/hammerhead/root/sbin/timetest
make: Leaving directory `/home/username/android_built/android'
The file installation part has been left out for clarity.
The following output is after I tried copying the timetest into frameworks/base/cmds as detailed in this question : android AOSP, adding new executable [.c] code. I also tried it directly.
I then looked at the entire phone including the xbin,bin directories . I also used find / -name "timetest", but the executable is nowhere to be found. What am I doing wrong?
I'm not actually sure how you are installing timetest to your device, but if you are just adb pushing the result to your device then you will likely have a hard time running that.
If you look at the Android.mk file for timetest you will see that it is labeled as "optional"
LOCAL_MODULE_TAGS := optional
However after grepping through all the make files, there is no build variant which includes this in a build. If you have your own device make file you can add it there, but if you just want to make this work quickly you can add it to the list of PRODUCT_PACKAGES in the build/target/product/core_minimal.mk file. There will be a list that looks something like:
PRODUCT_PACKAGES += \
BackupRestoreConfirmation \
DownloadProvider \
HTMLViewer \
MediaProvider \
Just add timetest into that list. After that do a make installclean and rebuild your device and you should have timetest included in sbin.

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.

how to run a shell command at the END of the Android.mk build process?

I am trying to copy a file from libs/arm/eabi in to res/raw at the end of the NDK build process using Android.mk
From some searching, I found that you can run a shell command to copy the file, like this:
$(shell cp $(LOCAL_PATH)/../../libs/armeabi/pcapd res/raw)
However, even if I put this at the end of my top-most Android.mk, it always tries to run this command first. How can I get it to run this after the build completes?
You can add to your Android.mk before #include $(BUILD_EXECUTABLE):
LOCAL_POST_INSTALL_CMD := \
cp $(LOCAL_PATH)/../../libs/armeabi/pcapd res/raw
Write a makefile that calls ndk-build and then your shell line. Build your project by executing make

Categories

Resources