简体   繁体   中英

How to compile a pure native executable for rooted Android

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM