Added cmake for building Android package

pull/2/head
Andrey Kamaev 13 years ago
parent d822989c8b
commit 6a13c9efc0
  1. 17
      CMakeLists.txt
  2. 15
      android/package/AndroidManifest.xml
  3. 95
      android/package/CMakeLists.txt
  4. 1
      android/package/info_lib/CMakeLists.txt
  5. 17
      android/package/info_lib/jni/Android.mk
  6. 2
      android/package/info_lib/jni/Application.mk
  7. 3
      android/package/info_lib/jni/include/info.h
  8. 31
      android/package/info_lib/jni/include/info_jni.h
  9. 18
      android/package/info_lib/jni/src/info.c
  10. BIN
      android/package/res/drawable/icon.png
  11. 6
      android/package/res/values/strings.xml
  12. 6
      android/service/engine/jni/NativeService/PackageInfo.h
  13. 4
      modules/nonfree/CMakeLists.txt

@ -152,13 +152,8 @@ OCV_OPTION(BUILD_TESTS "Build accuracy & regression tests"
OCV_OPTION(BUILD_WITH_DEBUG_INFO "Include debug info into debug libs (not MSCV only)" ON )
OCV_OPTION(BUILD_WITH_STATIC_CRT "Enables use of staticaly linked CRT for staticaly linked OpenCV" ON IF MSVC )
OCV_OPTION(BUILD_FAT_JAVA_LIB "Create fat java wrapper containing the whole OpenCV library" ON IF ANDROID AND NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX )
OCV_OPTION(BUILD_ANDROID_SERVICE "TBD" OFF IF ANDROID AND ANDROID_USE_STLPORT AND ANDROID_SOURCE_TREE )
if(DEFINED BUILD_opencv_nonfree AND NOT BUILD_opencv_nonfree)
OCV_OPTION(BUILD_ANDROID_PACKAGE "TBD" OFF IF ANDROID )
else()
unset(BUILD_ANDROID_PACKAGE CACHE)
endif()
OCV_OPTION(BUILD_ANDROID_SERVICE "Build OpenCV Manager for Google Play" OFF IF ANDROID AND ANDROID_USE_STLPORT AND ANDROID_SOURCE_TREE )
OCV_OPTION(BUILD_ANDROID_PACKAGE "Build platform-specific package for Google Play" OFF IF ANDROID )
# 3rd party libs
@ -230,15 +225,15 @@ else()
endif()
if(ANDROID)
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib/${ANDROID_NDK_ABI_NAME}")
set(3P_LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/3rdparty/lib/${ANDROID_NDK_ABI_NAME}")
set(LIBRARY_OUTPUT_PATH "${OpenCV_BINARY_DIR}/lib/${ANDROID_NDK_ABI_NAME}")
set(3P_LIBRARY_OUTPUT_PATH "${OpenCV_BINARY_DIR}/3rdparty/lib/${ANDROID_NDK_ABI_NAME}")
set(OPENCV_LIB_INSTALL_PATH sdk/native/libs/${ANDROID_NDK_ABI_NAME})
set(OPENCV_3P_LIB_INSTALL_PATH sdk/native/3rdparty/libs/${ANDROID_NDK_ABI_NAME})
set(OPENCV_CONFIG_INSTALL_PATH sdk/native/jni)
set(OPENCV_INCLUDE_INSTALL_PATH sdk/native/jni/include)
else()
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib")
set(3P_LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/3rdparty/lib${LIB_SUFFIX}")
set(LIBRARY_OUTPUT_PATH "${OpenCV_BINARY_DIR}/lib")
set(3P_LIBRARY_OUTPUT_PATH "${OpenCV_BINARY_DIR}/3rdparty/lib${LIB_SUFFIX}")
set(OPENCV_LIB_INSTALL_PATH lib${LIB_SUFFIX})
set(OPENCV_3P_LIB_INSTALL_PATH share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH})
set(OPENCV_INCLUDE_INSTALL_PATH include)

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.opencv.lib_v@OPENCV_VERSION_MAJOR@@OPENCV_VERSION_MINOR@_@ANDROID_PACKAGE_PLATFORM@"
android:versionCode="@OPENCV_VERSION_PATCH@@ANDROID_PACKAGE_RELEASE@"
android:versionName="@OPENCV_VERSION_PATCH@.@ANDROID_PACKAGE_RELEASE@" >
<uses-sdk android:minSdkVersion="@ANDROID_SDK_VERSION@" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
<application
android:icon="@drawable/icon"
android:label="@string/app_name" >
</application>
</manifest>

@ -1,2 +1,93 @@
#tbd
add_subdirectory(info_lib)
if(NOT ANDROID_PACKAGE_RELEASE)
set(ANDROID_PACKAGE_RELEASE 1)
endif()
if(NOT ANDROID_PACKAGE_PLATFORM)
if(ARMEABI_V7A)
if(NEON)
set(ANDROID_PACKAGE_PLATFORM armv7a_neon)
else()
set(ANDROID_PACKAGE_PLATFORM armv7a)
endif()
elseif(ARMEABI_V6)
set(ANDROID_PACKAGE_PLATFORM armv6)
elseif(ARMEABI)
set(ANDROID_PACKAGE_PLATFORM armv5)
elseif(X86)
set(ANDROID_PACKAGE_PLATFORM x86)
elseif(MIPS)
set(ANDROID_PACKAGE_PLATFORM mips)
else()
message(ERROR "Can not automatically determine the value for ANDROID_PACKAGE_PLATFORM")
endif()
endif()
if(NOT ANDROID_PACKAGE_PLATFORM_NAME)
if(ARMEABI_V7A)
if(NEON)
set(ANDROID_PACKAGE_PLATFORM_NAME "armeabi-v7a with NEON")
else()
set(ANDROID_PACKAGE_PLATFORM_NAME "armeabi-v7a")
endif()
elseif(ARMEABI_V6)
set(ANDROID_PACKAGE_PLATFORM_NAME "armeabi-v6")
elseif(ARMEABI)
set(ANDROID_PACKAGE_PLATFORM_NAME "armeabi")
elseif(X86)
set(ANDROID_PACKAGE_PLATFORM_NAME "x86")
elseif(MIPS)
set(ANDROID_PACKAGE_PLATFORM_NAME "mips")
else()
message(ERROR "Can not automatically determine the value for ANDROID_PACKAGE_PLATFORM_NAME")
endif()
endif()
if("${ANDROID_NATIVE_API_LEVEL}" MATCHES "[1-9][0-9]*$")
set(ANDROID_SDK_VERSION ${CMAKE_MATCH_0})
endif()
if(NOT ANDROID_SDK_VERSION GREATER 7)
set(ANDROID_SDK_VERSION 8)
endif()
set(PACKAGE_DIR "${OpenCV_BINARY_DIR}/package")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${ANDROID_MANIFEST_FILE}" "${PACKAGE_DIR}/${ANDROID_MANIFEST_FILE}" @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/res/values/strings.xml" "${PACKAGE_DIR}/res/values/strings.xml" @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/res/drawable/icon.png" "${PACKAGE_DIR}/res/drawable/icon.png" COPYONLY)
set(target_name "OpenCV_${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_VERSION_PATCH}_binary_pack_${ANDROID_PACKAGE_PLATFORM}")
get_target_property(opencv_java_location opencv_java LOCATION)
set(android_proj_target_files ${ANDROID_PROJECT_FILES})
ocv_list_add_prefix(android_proj_target_files "${PACKAGE_DIR}/")
android_get_compatible_target(android_proj_sdk_target ${ANDROID_SDK_VERSION})
set(APK_NAME "${PACKAGE_DIR}/bin/${target_name}-release-unsigned.apk")
file(GLOB camera_wrappers "${OpenCV_SOURCE_DIR}/3rdparty/lib/${ANDROID_NDK_ABI_NAME}/libnative_camera_r*.so")
set(CAMERA_LIB_COMMANDS "")
foreach(wrapper ${camera_wrappers})
list(APPEND CAMERA_LIB_COMMANDS COMMAND ${CMAKE_COMMAND} -E copy "${wrapper}" "${PACKAGE_DIR}/libs/${ANDROID_NDK_ABI_NAME}/")
endforeach()
add_custom_command(
OUTPUT "${APK_NAME}"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${PACKAGE_DIR}/libs"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${PACKAGE_DIR}/bin"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${PACKAGE_DIR}/gen"
COMMAND ${CMAKE_COMMAND} -E remove ${android_proj_target_files}
COMMAND ${CMAKE_COMMAND} -E make_directory "${PACKAGE_DIR}/src"
COMMAND ${CMAKE_COMMAND} -E make_directory "${PACKAGE_DIR}/libs/${ANDROID_NDK_ABI_NAME}/"
${CAMERA_LIB_COMMANDS}
COMMAND ${CMAKE_COMMAND} -E copy "${opencv_java_location}" "${PACKAGE_DIR}/libs/${ANDROID_NDK_ABI_NAME}/"
COMMAND ${ANDROID_EXECUTABLE} --silent update project --path "${PACKAGE_DIR}" --target "${android_proj_sdk_target}" --name "${target_name}"
COMMAND ${ANT_EXECUTABLE} -q -noinput -k release
COMMAND ${CMAKE_COMMAND} -E touch "${APK_NAME}"
WORKING_DIRECTORY "${PACKAGE_DIR}"
MAIN_DEPENDENCY "${opencv_java_location}"
DEPENDS "${PACKAGE_DIR}/${ANDROID_MANIFEST_FILE}" "${PACKAGE_DIR}/res/values/strings.xml" "${PACKAGE_DIR}/res/drawable/icon.png" ${camera_wrappers}
)
add_custom_target(android_package ALL SOURCES "${APK_NAME}" )
add_dependencies(android_package opencv_java)

@ -1,17 +0,0 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := \
src/info.c
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/include \
$(TOP)/frameworks/base/core/jni
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE := libopencvinfo
include $(BUILD_SHARED_LIBRARY)

@ -1,2 +0,0 @@
APP_ABI := armeabi-v7a x86
APP_PLATFORM := android-8

@ -1,3 +0,0 @@
// Function return list of shared libs seporated with ";" symbol
// in load order
const char* GetLibraryList();

@ -1,31 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_opencv_android_OpenCVLoader */
#ifndef _Included_org_opencv_android_OpenCVLoader
#define _Included_org_opencv_android_OpenCVLoader
#ifdef __cplusplus
extern "C" {
#endif
#undef org_opencv_android_OpenCVLoader_Success
#define org_opencv_android_OpenCVLoader_Success 0L
#undef org_opencv_android_OpenCVLoader_NoService
#define org_opencv_android_OpenCVLoader_NoService 1L
#undef org_opencv_android_OpenCVLoader_RestartRequired
#define org_opencv_android_OpenCVLoader_RestartRequired 2L
#undef org_opencv_android_OpenCVLoader_MarketError
#define org_opencv_android_OpenCVLoader_MarketError 3L
#undef org_opencv_android_OpenCVLoader_InitFailed
#define org_opencv_android_OpenCVLoader_InitFailed 255L
/*
* Class: org_opencv_android_OpenCVLoader
* Method: GetLibraryList
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_opencv_android_StaticHelper_getLibraryList
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif

@ -1,18 +0,0 @@
#include "info.h"
#include <jni.h>
#ifndef LIB_STRING
#define LIB_STRING "libtbb.so;libopencv_java.so"
#endif
const char* GetLibraryList()
{
return LIB_STRING;
}
JNIEXPORT jstring JNICALL Java_org_opencv_android_StaticHelper_getLibraryList(JNIEnv* jenv, jclass clazz)
{
jstring result = (*jenv)->NewStringUTF(jenv, LIB_STRING);
return result;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">OCV @OPENCV_VERSION_MAJOR@.@OPENCV_VERSION_MINOR@ binary pack for @ANDROID_PACKAGE_PLATFORM_NAME@</string>
</resources>

@ -8,7 +8,7 @@
#define ARCH_X64_NAME "x64"
#define ARCH_ARMv5_NAME "armv5"
#define ARCH_ARMv6_NAME "armv6"
#define ARCH_ARMv7_NAME "armv7"
#define ARCH_ARMv7_NAME "armv7a"
#define ARCH_ARMv8_NAME "armv8"
#define FEATURES_HAS_VFPv3d16_NAME "vfpv3d16"
@ -26,7 +26,7 @@
class PackageInfo
{
{
public:
PackageInfo(const std::string& version, int platform, int cpu_id);
PackageInfo(const std::string& fullname, const std::string& install_path, const std::string& package_version = "0.0");
@ -38,7 +38,7 @@ public:
bool operator==(const PackageInfo& package) const;
static const std::map<int, std::string> PlatformNameMap;
bool IsValid() const;
protected:
static std::map<int, std::string> InitPlatformNameMap();
std::string Version;

@ -1,2 +1,6 @@
if(BUILD_ANDROID_PACKAGE)
ocv_module_disable(nonfree)
endif()
set(the_description "Functionality with possible limitations on the use")
ocv_define_module(nonfree opencv_imgproc opencv_features2d)

Loading…
Cancel
Save