*Binaries for all supported CPU architectures are generated here. Use adb shell cat /proc/cpuinfo to find out the CPU architecture and set APP_ABI as per Supported ABIs.

Android Studio

The example of building executable shown below is based on HelloJNI sample. I recommend to use it in order to preserve consistency of the Gradle build system (Gradle 2.8) / plugin version (gradle-experimental:0.4.0).

AFAIK, by the time of this writing android.ndk module of build.gradle doesn't have the option to build executables yet. In this case the steps are as follows.

Use regular *.mk files by setting the location of source files to non-existing folder and jniLibs location to libs folder in build.gradle:

**If you run into Error:Execution failed for task ':app:ndkBuild'. A problem occurred starting process 'command 'ndk-build(.cmd)'', try setting the full path to ndk-build(.cmd) command.

III. PUSH BINARY INTO DEVICE

Push mycommand binary from project_root/libs/<abi> (Eclipse) or project_app_root/src/main/libs/<abi> (Android Studio) into your device. Keep in mind that files on SD card aren't executable, so the binary should be pushed into the device's internal storage. Depending of whether device is rooted or not you have the following options:

On non-rooted device you can push the binary to /data/local/tmp:

adb push mycommand /data/local/tmp

On rooted device you can push the binary to SD card and then copy it to /system/bin (after remounting the partition in read-write mode) along with the other executable files: