How to run C++ application in Android SHELL

老子叫甜甜 提交于 2020-01-01 02:51:26

问题


I want to run hello world written on C++ and compiled with Android toolchain 9, but I faced with issue: by default I have no permissions to launch it and I can't change permissions using chmod`.

I used Android 2.3.3 - Api Level 10

Application was compiled by cross compiler for API level 9

Procedure:

Compile application:

~/toolchain_andr9/bin/ arm-linux-androideabi-g++ helloworld.cpp

Then send application to SDCARD on the emulator:

>adb push a.out /mnt/sdcard

then go to SHELL and try to run a.out:

>adb shell
> 
>/mnt/sdcard/a.out

And result is:

>`/mnt/sdcard/a.out: permission denied`

command ls -l shows rights for a.out:

>`----rwxr-x system   sdcard_rw   863656 2012-04-12 22:42 a.out`

I tried to change permissions:

>chmod 777 /mnt/sdcard/a.out

But rights don't change:

>`----rwxr-x system   sdcard_rw   863656 2012-04-12 22:42 a.out`

I think I have left some important thing using android.

Could anybody help me and give me a way how to run application in `Android SHELL?

Thanks a lot.

P.S. sorry for my English =)


回答1:


By default, the SD card is mounted with option noexec, that disallows the execution of any file on the card, no matter what it's permissions(even -rwxrwxrwx), so you need to move the file to another location and then execute it.

The easiest is to move the file to /data/local/tmp/ and execute it using the full path (usual POSIX PATH semantics).

> adb push a.out /data/local/tmp/a.out
> adb shell
> chmod 755 /data/local/tmp/a.out
> /data/local/tmp/a.out

This does not require root access and survives reboot.




回答2:


If you have rooted your phone you can do a mount -o remount,rw /mnt/sdcard and it should run.

I've tried it on my Android.



来源:https://stackoverflow.com/questions/10133274/how-to-run-c-application-in-android-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!