I've got an application project which includes a jni native code (example.c) with the following makefile:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := example
LOCAL_SRC_FILES := example.c
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
include $(BUILD_EXECUTABLE)
So I'm building it like an executable and everything goes right. Is the executable "packed" with the application? If yes, how do I get its path or its location in memory, so I can run it from the java code?
PS: I'm not building the native code as a shared library because I want to run a main function as root with shell commands, like this:
chmod 777 /path/exe
/path/exe
Create a directory:
/jni
and another directory/libs
. Now put yourexample.c
and yourAndroid.mk
inside the/jni
directory. Nowcd
to the/jni
directory and type the commandndk-build
. If your makefile is correct and there are no errors in you source files the under the/libs
directory another new directory called/armeabi
would be created. Inside this directory, your executable would be present.To execute this executable the android device must be rooted or you can use the android emulator provided with SDK.
Further you need to place this executable into
/data/local/
location of your android device (because even though your device is rooted, you will not have execute permissions from other locations.you can do so using the below command:
Now enter the
adb shell
mode and cd to/data/local/
.Change your file permissions:
chmod example 777
Now in this same location you can place your shell file. Also you can access your sdcard and other folders from this directory.
Hope this is helpful to you. If everything works, don't forget to accept the answer.