Android:在adb shell上执行程序 [英] Android: Executing a program on adb shell

查看:982
本文介绍了Android:在adb shell上执行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Android.mk中的"include $(BUILD_EXECUTABLE)" 命令创建了一个可执行文件. 我的要求是在abd shell上执行上面生成的可执行文件.

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.

我尝试过:

下面是我的C代码,它是使用ndk-build命令编译的:

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;
}

以下是我的 Android.mk 文件内容:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := HelloExecutable
LOCAL_SRC_FILES := hello.c
include $(BUILD_EXECUTABLE)

当我执行命令 ndk-build 时,将生成以下文件:

When i execute the command ndk-build the following file is generated:

projectRoot-> libs-> HelloExecutable

projectRoot->libs->HelloExecutable

我的工作是在adb shell上执行上面生成的文件.因此,我首先使用以下命令将文件推送到sdcard:

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/

现在,我使用以下命令切换到adb shell: $ adb shell 命令(此处使用的是模拟器).

Now i switch to adb shell using: $adb shell command(here i'm using an emulator).

然后,我将权限更改为: chmod 777/sdcard/HelloExecutable

Then i change the permissions as: chmod 777 /sdcard/HelloExecutable

执行上述命令后,我将获得我的 HelloExecutable 文件的执行权限.

Once the above command is executed, i get the executing permissions for my HelloExecutable file.

然后将当前工作目录更改为sdcard.即 cd/sdcard/

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.

推荐答案

检查是否已使用noexec选项安装了SD卡.尝试将文件复制到/data等另一个分区,然后从那里执行.

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

这篇关于Android:在adb shell上执行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆