Android: Executing a program on adb shell

2019-02-28 10:48发布

问题:

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.

回答1:

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