Skip to content

robertwgh/AndroidNativeLauncher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Android NDK Native Program Launcher

An Android application which allows to execute native program built by ndk-buld.

Please read this article for more details: http://web.guohuiwang.com/technical-notes/nativelauncher

Screenshot

NativeLauncher screenshot

Benifits

  • Do not require ROOT permission. Enabling native program execution on non-rooted devices.
  • Allows to run native code without USB cable and ADB. This is very important for some special purpose, for example, if we want to measure power consumption of the devices when running the native code, we don't want to connect USB cable which will provide power to the device.
  • Help debug native code before porting it using JNI code in an Android app.

Features

  • Support loading native program from sdcard.
  • Support command line arguments.
  • Allow the user to set up LD_LIBRARY_PATH.
  • Support subfolders. Input files and configurations loaded by the native program can be put in subfolders, in the native program, use relative path to access them.
  • Support output files. Output files can be retrieved from the working directory.

Install

  • Install is simple. Download the apk file under android_apk, and install it on your Android device. Then you are good to go.

Instructions

  1. Copy your native program (compiled by ndk-build) in a folder on your sdcard, e.g. /sdcard/test/.
  2. Copy all dependent shared libraries (.so) to that folder.
  3. Copy input files to the same folder.
  4. Press the button "Load native program".
  5. Set command line arguments if there is any.
  6. Press button "Run" to execute the program.
  7. Check results under your folder, such as /sdcard/test/.

FAQ

  1. Q: Where is the working directory?
  • A: The working directory is the directory the executable located.
  1. Q: How to set LD_LIBRARY_PATH? What is the library loading order?
  • A: In the textedit field, type your custom library path. Please notice that, your working directory will be added to LD_LIBRARY_PATH automatically. For example, if you type "mylib" in the field, the LD_LIBRARY_PATH will be set as LD_LIBRARY_PATH=mypath:working_directory:$LD_LIBRARY_PATH.
  1. Q: How to use subfolder?
  • A: Subfolder can be accessed via relative path. For example, if we have a folder named "image" in working directory containing an input image "lena.png", in your code, you can access it via image/lena.png. Your output files will also be under the working directory.
  1. Q: I was not able to load the binary after I clicked "Load Native Program" button?
  • A: On some devices (especially some factory testing devcies), there is no default file explorer. Please install one from the Google Play Store. Basically, any file explorer can do the job. The "ES file explorer" is a good one to start, if you have no preference.

Examples

Two examples are provided to demonstrate the usage of native program launcher. Pre-compiled binaries are provided under bin folder. But you can also compile them using ndk-bulid.

  1. Compile the examples with Android NDK:
  2. Have ndk installed and ndk-build is in the system path.
  3. in shell, run ./build_examples.sh. Then you have the binareis in bin folder
$ cd examples
$ ./build_examples.sh
  1. example1 shows basic usage, and command line arguments. You can set up command line arguments, and they will be displayed one by one.
  2. example2 shows the case where we have executable file along with shared library.

License

Copyright 2015 Guohui Wang

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

An Android application which allows to execute native NDK program.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published