Skip to content

Android compilation

Matthew Hill edited this page Aug 1, 2014 · 2 revisions

This is a guide to compile the library for android contributed by Jérémy VIENNE:

Tutorial for compiling OpenALPR for Android devices

[Step 0]

  • Download and deploy android-ndk
  • Make a symbolic link to android-ndk root folder to /opt

[Step 1]

[Step 2]

[Step 3]

  • Download and install the Android CMake project (https://code.google.com/p/android-cmake/) You should end up with a toolchain for generating android projects. If you got to choose which compiler to use, I recommend the gcc4.6 as I did not achieve compiling OpenALPR with a toolchain pointing to the gcc4.8 compiler...
  • Make a symbolic link to android-toolchain folder inside /opt (ie : sudo ln -s PATH_TO_ANDROID_TOOLCHAIN /opt/android-toolchain). (The android-toolchain folder is generated during the deployment of Android CMake project !)

[Step 4]

  • Download the openalpr-master from github (https://github.com/openalpr/openalpr)

  • Create a folder "build" inside openalpr-master directory

  • Go to the src directory and edit the CMakeLists.txt file :

  • Replace this line : SET(OpenCV_DIR "${CMAKE_SOURCE_DIR}/../libraries/opencv/") with : SET(OpenCV_DIR "path_to_OpenCV4Android/sdk/native/jni")

  • Then comment the section for generating alprd (or just remove it) :

  • Compile the alprd library on Unix-based OS

    IF (NOT WIN32) ADD_EXECUTABLE( alprd daemon.cpp videobuffer.cpp daemon/beanstalk.c daemon/beanstalk.cc daemon/uuid.cpp )

    TARGET_LINK_LIBRARIES(alprd openalpr support uuid curl log4cplus ${OpenCV_LIBS} ${Tesseract_LIBS} ) ENDIF()
  • Open CMake

  • Point the Source code to the openalpr-master/src directory

  • Point the Build path to the openalpr-master/build directory

  • Press the "Configure" button

  • Choose "Unix Makefiles" (default) and select "Specify toolchain for cross-compiling" then click "Next"

  • Specify the toolchain file to use : if you achieved step 3, it should be located under $ANDROID_CMAKE/toolchain/android.toolchain.cmake (be sure to replace the $ANDROID_CMAKE with its corresponding absolute path)

  • Click on finish

  • There should not be any error but some warnings... it's ok

  • Press Generate

[Step 5]

  • Go to the build directory and edit this file : misc_utilities/CMakeFiles/benchmark.dir/link.txt : remove the -lpthread option (there should be only one line like this). Save and exit.
  • Open a file explorer and go to path_to_tess-two/tess-two/jni/com_googlecode_tesseract_android/src Now search every header file (Press the search button and type in ".h" )
  • Copy and paste every header file to openalpr-master/src/openalpr/tesseract (you should create this directory first)
  • Creates these directories "libraries/tesseract-ocr/api/.libs" in the root path of openalpr-master (mkdir -p libraries/tesseract-ocr/api/.libs)
  • Copy and paste path_to_tess-two/tess-two/libs/armeabi-v7a/libtess.so to openalpr-master/libraries/tesseract-ocr/api/.libs/libtesseract.so (be sure to rename it from libtess.so to libtesseract.so !)
  • Open a terminal and go to the build folder (openalpr-master/build)
  • Do "make"
  • Everything should compile smoothly. You can find the alpr library in the openalpr-master/src/libs/armeabi-v7a

Android.mk

LOCAL_PATH := $(call my-dir)
LIB_PATH := $(LOCAL_PATH)/../libs/armeabi-v7a

include $(CLEAR_VARS)

LOCAL_MODULE := leptonica
LOCAL_SRC_FILES := liblept.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := tesseract
LOCAL_SRC_FILES := libtess.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := simpleini
LOCAL_SRC_FILES := libsimpleini.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := support
LOCAL_SRC_FILES := libsupport.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := openalpr
LOCAL_SRC_FILES := libopenalpr-static.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

OPENCV_INSTALL_MODULES:=on
OPENCV_CAMERA_MODULES:=off

include path_to_opencv4android/OpenCV.mk

LOCAL_MODULE := nativealpr
LOCAL_SRC_FILES := NativeAlpr.cpp
LOCAL_SHARED_LIBRARIES += tesseract leptonica
LOCAL_STATIC_LIBRARIES += openalpr support simpleini

include $(BUILD_SHARED_LIBRARY)

Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a

In the Android.mk file, the NativeAlpr.cpp file contains the necessary native code to use the OpenALPR library