I'm using eclipse with the NDK to port my C++ application to Android. On Linux, it is an application that you invoke with arguments in the shell to perform a task, no GUI is provided, it is just a command line interface. Presently, I have added a very basic GUI wrapper in java that encapsulates the argument specification that is passed to the ported C++ code in the NDK, however, I would like to also have an application that can be invoked when I ssh into my android phone.
On Android, I see that some applications have the ability to be launched from the shell. For example, the SSH Droid
installed from the Google Play Store, has in addition to its GUI, a shell invokable version. I see this under the pathname /data/data/berserker.android.apps.sshdroid/dropbear/ssh
whereas its APK is located at /data/app/berserker.android.apps.sshdroid-1.apk
. For my APK, I find no executables in /data/data/com.mydomain.myapp-37.apk
, only the directories cache
, files
, and lib
.
Using Eclipse, how can I package natively executable binaries in my application's APK archive? Once present in my APK, how can I in the installation automate the extraction and setting executable permissions so that I can launch it through the shell? It would appear that SSH Droid has done both of these things, I would like to do likewise. Is there a simple example that shows how this is done?
Do I even need an apk, can I somehow just create a command line interface executable more in line with my existing Linux port version?
How are arguments specified for the shell CLI? Do you use argc
and argv
like in C++ applications?
For me, I didn't need eclipse nor any java code in my application. My application that was being ported from Linux, already had a set of makefiles already in place. I was able to use my existing makefile system by way of the standalone tool chain portion of the NDK.
This answer got me going with the standalone tool chain. In my case, here is how I invoked it where I am cross compiling from my Macintosh, having already installed the NDK at /Users/me/Development/android-ndk-r10d
:
ANDROID_NDK=/Users/me/Development/android-ndk-r10d
SYSROOT=$(ANDROID_NDK)/platforms/android-19/arch-arm
${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh --platform=android-19 --install-dir=${ANDROID_NDK}/myapp-android-toolchain --ndk-dir=/Users/me/Development/android-ndk-r10d --toolchain=arm-linux-androideabi-4.8 --system=darwin-x86_64
With this setup, I launched my build like this:
cd ~/base/of/myapp/src/
ANDROID_NDK=/Users/me/Development/android-ndk-r10d PATH=${ANDROID_NDK}/myapp-android-toolchain/bin:$PATH make
After I fixed some issues with config for my cross-compilation in some third-party libraries I'm using, I had a working build. Next, I wanted to install it on my phone:
# Push to a location with write permission (sdcard):
cd ~/base/of/myapp/bin/ # My build puts the executable here.
adb push myapp /sdcard/
# Go into phone and complete the install manually:
adb shell
su
mount -oremount,rw rootfs /system # /vendor/bin is in /system mount.
# One time creation of /vendor/bin (that is in the PATH by default):
mkdir /vendor/bin
# Copy the myapp executable over
cp /sdcard/myapp /vendor/bin/myapp
Now, I can invoke myapp from the shell on my phone, like a normal command line interface Linux application. The argc
and argv
from my original Linux code work as written in the Android build by this process.