0

I'm working on a rooted Android 2.3. In my application, using jni mechanism I call a native (c/c++) function that needs root permissions to operate, thats why it always fails (even though my phone is rooted - because the specific process/app need to grant the root permission) .

I want to move that function to an external executable that will run on the linux by the command "sudo exec_name" that I will run from java (Runtime.getRuntime().exec("sudo ...");)

So

1) How can I compile a native executable? (not a library as usual [.so])

2) After I have a stand alone executable, where in the system I have to put it and with what permissions?

1 Answer 1

1

To compile a native executable use include $(BUILD_EXECUTABLE) instead of include $(BUILD_SHARED_LIBRARY). There is an example in NDK called test-libstdc++ which show how to build the simplest native executable.

Then you need to put it in executable location like /data/local and call chmod 777 in order to make it executable. After that you can run it via shell.

I want to move that function to an external executable that will run on the linux by the command "sudo exec_name" that I will run from java (Runtime.getRuntime().exec("sudo ...");)

In this case your workflow will look like this:

  • You compile your code into native executable file and put it in app assets
  • At start you need to copy yoru executable file from assets to the /system/bin
  • Allow to run it using chmod 777
  • Actually run your executable

The first three points should be done only once.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.