Skip to content

Latest commit

 

History

History
167 lines (128 loc) · 6.45 KB

README.md

File metadata and controls

167 lines (128 loc) · 6.45 KB

NNStreamer API Library for Android

Prerequisite

We assume that you already have experienced Android application developments with Android Studio.

  • Host PC:
    • OS: Ubuntu 16.04 x86_64 LTS
    • Android Studio: Ubuntu version
    • Android SDK: Min version 24 (Nougat)
    • Android NDK: Use default ndk-bundle in Android Studio
    • GStreamer: gstreamer-1.0-android-universal-1.16.1

Build library

Environment variables

First of all, you need to set-up the development environment as following:

$ export ANDROID_DEV_ROOT=$HOME/android               # Set your own path (The default path will be "$HOME/Android".)
$ mkdir -p $ANDROID_DEV_ROOT/tools/sdk
$ mkdir -p $ANDROID_DEV_ROOT/gstreamer-1.0
$ mkdir -p $ANDROID_DEV_ROOT/workspace
$
$ vi ~/.bashrc
# Environment variables for developing a NNStreamer application
#
export JAVA_HOME=/opt/android-studio/jre            # JRE path in Android Studio
export ANDROID_DEV_ROOT=$HOME/android               # Set your own path (The default path will be "$HOME/Android".)
#
# $ANDROID_DEV_ROOT/tools/sdk                    # Android SDK root directory (default location: $HOME/Android/Sdk)
# $ANDROID_DEV_ROOT/gstreamer-1.0                # GStreamer binaries
# $ANDROID_DEV_ROOT/workspace/nnstreamer         # NNStreamer cloned git repository
#
export ANDROID_SDK=$ANDROID_DEV_ROOT/tools/sdk      # Android SDK (The default path will be "$HOME/Android/Sdk".)
export ANDROID_HOME=$ANDROID_SDK
export GSTREAMER_ROOT_ANDROID=$ANDROID_DEV_ROOT/gstreamer-1.0
export NNSTREAMER_ROOT=$ANDROID_DEV_ROOT/workspace/nnstreamer

Download Android Studio

Download and install Android Studio to compile an Android source code. You can see the installation guide here.

For example,

$ firefox  https://developer.android.com/studio
Then, download "Android Studio" in the /opt folder.
$ cd /opt
$ wget https://dl.google.com/dl/android/studio/ide-zips/3.4.0.18/android-studio-ide-183.5452501-linux.tar.gz
$ tar xvzf ./android-studio-ide-183.5452501-linux.tar.gz

Now, run the android studio from ./android-studio/bin/studio.sh and install SDK to $ANDROID_SDK. Next, agree to the licenses for the Android SDK.

$ cd $ANDROID_SDK/tools/bin
$ yes | ./sdkmanager --licenses

Download NDK

Use the default NDK in Android Studio. To install NDK in Android Studio, navigate to configure -> Appearance & Behavior -> System Settings -> Android SDK -> SDK Tools and then select NDK.

If you need to set a specific version, download and decompress it to compile normally a GStreamer-based plugin (e.g., NNStreamer). You can download older version from here.

Download GStreamer binaries

You can get the prebuilt GStreamer binaries from here.

For example,

$ cd $ANDROID_DEV_ROOT/gstreamer-1.0
$ wget https://gstreamer.freedesktop.org/data/pkg/android/1.16.1/gstreamer-1.0-android-universal-1.16.1.tar.xz
$ tar xJf gstreamer-1.0-android-universal-1.16.1.tar.xz

Modify the gstreamer-1.0.mk file for NDK build to prevent build error. Supported target ABIs are arm64 and armv7.

$GSTREAMER_ROOT_ANDROID/{Target-ABI}/share/gst-android/ndk-build/gstreamer-1.0.mk
  • Add directory separator.
@@ -127,2 +127,2 @@

GSTREAMER_PLUGINS_CLASSES    := $(strip \
            $(subst $(GSTREAMER_NDK_BUILD_PATH),, \
            $(foreach plugin,$(GSTREAMER_PLUGINS), \
-           $(wildcard $(GSTREAMER_NDK_BUILD_PATH)$(plugin)/*.java))))
+           $(wildcard $(GSTREAMER_NDK_BUILD_PATH)/$(plugin)/*.java))))

GSTREAMER_PLUGINS_WITH_CLASSES := $(strip \
            $(subst $(GSTREAMER_NDK_BUILD_PATH),, \
            $(foreach plugin, $(GSTREAMER_PLUGINS), \
-           $(wildcard $(GSTREAMER_NDK_BUILD_PATH)$(plugin)))))
+           $(wildcard $(GSTREAMER_NDK_BUILD_PATH)/$(plugin)))))

@@ -257,1 +257,1 @@

copyjavasource_$(TARGET_ARCH_ABI):
  $(hide)$(call host-mkdir,$(GSTREAMER_JAVA_SRC_DIR)/org/freedesktop/gstreamer)
    $(hide)$(foreach plugin,$(GSTREAMER_PLUGINS_WITH_CLASSES), \
        $(call host-mkdir,$(GSTREAMER_JAVA_SRC_DIR)/org/freedesktop/gstreamer/$(plugin)) && ) echo Done mkdir
    $(hide)$(foreach file,$(GSTREAMER_PLUGINS_CLASSES), \
-       $(call host-cp,$(GSTREAMER_NDK_BUILD_PATH)$(file),$(GSTREAMER_JAVA_SRC_DIR)/org/freedesktop/gstreamer/$(file)) && ) echo Done cp
+       $(call host-cp,$(GSTREAMER_NDK_BUILD_PATH)/$(file),$(GSTREAMER_JAVA_SRC_DIR)/org/freedesktop/gstreamer/$(file)) && ) echo Done cp

Download NNStreamer source code

$ cd $ANDROID_DEV_ROOT/workspace
$ git clone https://github.com/nnsuite/nnstreamer.git

Build Android API

Run the build script in NNStreamer.

  • Build options
    1. target_abi: Default arm64-v8a, specify the ABI (armeabi-v7a, arm64-v8a) to be built for with --target_abi={TARGET-ABI}.
    2. build_type: Get the minimized library with GStreamer core elements --build_type=lite.
    3. run_test: Run the instrumentation test --run_test=yes.
$ cd $NNSTREAMER_ROOT
$ bash ./api/android/build-android-lib.sh

After building the Android API, you can find the library(.aar) in $NNSTREAMER_ROOT/android_lib.

  • Build result
    1. nnstreamer.aar: NNStreamer library
    2. nnstreamer-native.zip: shared objects and header files for native developer

Run the unit-test (Optional)

To run the unit-test, you will need an Android Emulator running or a physical device connected and in usb debugging mode. Make sure to select the appropriate target ABI for the emulator. Before running the unit-test, you should download the test model and copy it into your target device manually.

Make directory and copy test model and label files into the internal storage of your own Android target device.

You can download these files from nnsuite testcases repository.

# You must put the below model and label files in the internal storage of your Android target device.
{INTERNAL_STORAGE}/nnstreamer/test/mobilenet_v1_1.0_224_quant.tflite
{INTERNAL_STORAGE}/nnstreamer/test/add.tflite
{INTERNAL_STORAGE}/nnstreamer/test/labels.txt
{INTERNAL_STORAGE}/nnstreamer/test/orange.png

To check the testcases, run the build script with an option --run_test=yes. You can find the result in $NNSTREAMER_ROOT/android_lib.

$ cd $NNSTREAMER_ROOT
$ bash ./api/android/build-android-lib.sh --run_test=yes