2

I am trying to run a simple c++ code on my mobile phone. My application idea is to run a local server on my android phone and connect to this server with a browser or an android application.

To do this, I have compiled a simple main.c code to see if I run a c code on the Android platform with using NDK. I think it has compiled correctly and it is ready to run on my mobile phone. Then to send the executable file to my mobile phone I have used adb command on my Linux shell like;

adb push test /storage/self/primary/Android/data
adb shell chmod 777 /storage/self/primary/Android/data/test

Then when I connect to my phone I am using adb shell /storage/self/primary/Android/data/test command, it returns me can't execute: Permission denied output.

Actually, I have a few steps to finish my project. For example, I want to run this executable file without using the terminal.

Anyway, How can I run this executable file on my mobile phone?

SayMyName
  • 461
  • 5
  • 17
  • There are quite a lot of constraints on native applications on android, opening sockets needs special rigths. Is your phone rooted (or are you using a custom image)? With a vanilla android, there are little chances that you manage to do that, IMHO (that said, itdepends on the android version, a gingerbread may not be that securized) – OznOg May 08 '19 at 13:23
  • I am using custom image(not rooted) and I have Android version 9. Is there any way to run this file on my mobile phone without any setup change. – SayMyName May 08 '19 at 13:42
  • if you have strace installed on your image, try running `strace /path/to/test` and look at the output where the EPERM comes; may be a start for your investigations, but I must say, Android's permissions (especially if you have selinux acivated) is a full time job... – OznOg May 08 '19 at 14:44
  • 2
    Many locations on the device are banned from execution for security concerns. `/storage` is one of them. The one that is usually available for **adb shell** is `/data/local/tmp`. – Alex Cohn May 08 '19 at 21:36
  • @AlexCohn It is not working ` adb: error: failed to copy 'test' to '/data/local/test': remote couldn't create file: Permission denied` – SayMyName May 09 '19 at 05:49
  • Why do you need it as a standalone executable? Can you re-engineer it as a regular JNI library? – Seva Alekseyev May 09 '19 at 19:49
  • `/data/local/tmp/test`, not `/data/local/test` – Dan Albert May 20 '19 at 21:10
  • [How to build an executable for Android shell](https://stackoverflow.com/q/35231168/3290339) – Onik Jul 29 '19 at 20:19

0 Answers0