2018-02-18 06:36:15 +08:00
|
|
|
// This file is part of OpenCV project.
|
|
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
|
|
// of this distribution and at http://opencv.org/license.html.
|
|
|
|
|
|
|
|
//
|
|
|
|
// Notes about integration OpenCV into existed Android Studio application project are below (application 'app' module should exist).
|
|
|
|
//
|
|
|
|
// This file is located in <OpenCV-android-sdk>/sdk directory (near 'etc', 'java', 'native' subdirectories)
|
|
|
|
//
|
|
|
|
// Add module into Android Studio application project:
|
|
|
|
//
|
|
|
|
// - Android Studio way:
|
|
|
|
// (will copy almost all OpenCV Android SDK into your project, ~200Mb)
|
|
|
|
//
|
|
|
|
// Import module: Menu -> "File" -> "New" -> "Module" -> "Import Gradle project":
|
|
|
|
// Source directory: select this "sdk" directory
|
|
|
|
// Module name: ":opencv"
|
|
|
|
//
|
|
|
|
// - or attach library module from OpenCV Android SDK
|
|
|
|
// (without copying into application project directory, allow to share the same module between projects)
|
|
|
|
//
|
|
|
|
// Edit "settings.gradle" and add these lines:
|
|
|
|
//
|
|
|
|
// def opencvsdk='<path_to_opencv_android_sdk_rootdir>'
|
|
|
|
// // You can put declaration above into gradle.properties file instead (including file in HOME directory),
|
|
|
|
// // but without 'def' and apostrophe symbols ('): opencvsdk=<path_to_opencv_android_sdk_rootdir>
|
|
|
|
// include ':opencv'
|
|
|
|
// project(':opencv').projectDir = new File(opencvsdk + '/sdk')
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Add dependency into application module:
|
|
|
|
//
|
|
|
|
// - Android Studio way:
|
|
|
|
// "Open Module Settings" (F4) -> "Dependencies" tab
|
|
|
|
//
|
|
|
|
// - or add "project(':opencv')" dependency into app/build.gradle:
|
|
|
|
//
|
|
|
|
// dependencies {
|
|
|
|
// implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
|
|
// ...
|
|
|
|
// implementation project(':opencv')
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Load OpenCV native library before using:
|
|
|
|
//
|
|
|
|
// - avoid using of "OpenCVLoader.initAsync()" approach - it is deprecated
|
|
|
|
// It may load library with different version (from OpenCV Android Manager, which is installed separatelly on device)
|
|
|
|
//
|
2018-04-03 21:41:48 +08:00
|
|
|
// - use "System.loadLibrary("opencv_java4")" or "OpenCVLoader.initDebug()"
|
2018-02-18 06:36:15 +08:00
|
|
|
// TODO: Add accurate API to load OpenCV native library
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Native C++ support (necessary to use OpenCV in native code of application only):
|
|
|
|
//
|
|
|
|
// - Use find_package() in app/CMakeLists.txt:
|
|
|
|
//
|
2021-10-02 06:04:23 +08:00
|
|
|
// find_package(OpenCV @OPENCV_VERSION_MAJOR@.@OPENCV_VERSION_MINOR@ REQUIRED java)
|
2018-02-18 06:36:15 +08:00
|
|
|
// ...
|
|
|
|
// target_link_libraries(native-lib ${OpenCV_LIBRARIES})
|
|
|
|
//
|
|
|
|
// - Add "OpenCV_DIR" and enable C++ exceptions/RTTI support via app/build.gradle
|
|
|
|
// Documentation about CMake options: https://developer.android.com/ndk/guides/cmake.html
|
|
|
|
//
|
|
|
|
// defaultConfig {
|
|
|
|
// ...
|
|
|
|
// externalNativeBuild {
|
|
|
|
// cmake {
|
|
|
|
// cppFlags "-std=c++11 -frtti -fexceptions"
|
|
|
|
// arguments "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni" // , "-DANDROID_ARM_NEON=TRUE"
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// - (optional) Limit/filter ABIs to build ('android' scope of 'app/build.gradle'):
|
|
|
|
// Useful information: https://developer.android.com/studio/build/gradle-tips.html (Configure separate APKs per ABI)
|
|
|
|
//
|
|
|
|
// splits {
|
|
|
|
// abi {
|
|
|
|
// enable true
|
2018-11-06 01:39:09 +08:00
|
|
|
// universalApk false
|
2018-02-18 06:36:15 +08:00
|
|
|
// reset()
|
|
|
|
// include 'armeabi-v7a' // , 'x86', 'x86_64', 'arm64-v8a'
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
|
|
|
|
apply plugin: 'com.android.library'
|
2023-12-14 23:38:35 +08:00
|
|
|
apply plugin: 'maven-publish'
|
2024-07-04 18:26:37 +08:00
|
|
|
try {
|
|
|
|
@KOTLIN_PLUGIN_DECLARATION@
|
|
|
|
println "Configure OpenCV with Kotlin"
|
|
|
|
} catch (Exception e) {
|
|
|
|
println "Configure OpenCV without Kotlin"
|
|
|
|
}
|
2018-02-18 06:36:15 +08:00
|
|
|
|
2020-01-04 00:15:35 +08:00
|
|
|
def openCVersionName = "@OPENCV_VERSION@"
|
2020-01-15 13:34:42 +08:00
|
|
|
def openCVersionCode = ((@OPENCV_VERSION_MAJOR@ * 100 + @OPENCV_VERSION_MINOR@) * 100 + @OPENCV_VERSION_PATCH@) * 10 + 0
|
2020-01-04 00:15:35 +08:00
|
|
|
|
|
|
|
println "OpenCV: " +openCVersionName + " " + project.buildscript.sourceFile
|
2018-02-18 06:36:15 +08:00
|
|
|
|
|
|
|
android {
|
2023-04-28 18:41:39 +08:00
|
|
|
@OPENCV_ANDROID_NAMESPACE_DECLARATION@
|
2018-11-06 01:39:09 +08:00
|
|
|
compileSdkVersion @ANDROID_COMPILE_SDK_VERSION@
|
2018-02-18 06:36:15 +08:00
|
|
|
|
|
|
|
defaultConfig {
|
2018-11-06 01:39:09 +08:00
|
|
|
minSdkVersion @ANDROID_MIN_SDK_VERSION@
|
|
|
|
targetSdkVersion @ANDROID_TARGET_SDK_VERSION@
|
2019-07-12 04:04:05 +08:00
|
|
|
|
2020-01-04 00:15:35 +08:00
|
|
|
versionCode openCVersionCode
|
|
|
|
versionName openCVersionName
|
|
|
|
|
2019-07-12 04:04:05 +08:00
|
|
|
externalNativeBuild {
|
|
|
|
cmake {
|
|
|
|
arguments "-DANDROID_STL=@ANDROID_STL@"
|
|
|
|
targets "opencv_jni_shared"
|
|
|
|
}
|
|
|
|
}
|
2018-02-18 06:36:15 +08:00
|
|
|
}
|
|
|
|
|
2023-04-28 18:41:39 +08:00
|
|
|
compileOptions {
|
|
|
|
sourceCompatibility JavaVersion.VERSION_@ANDROID_GRADLE_JAVA_VERSION_INIT@
|
|
|
|
targetCompatibility JavaVersion.VERSION_@ANDROID_GRADLE_JAVA_VERSION_INIT@
|
|
|
|
}
|
|
|
|
|
2018-02-18 06:36:15 +08:00
|
|
|
buildTypes {
|
2019-05-19 01:13:39 +08:00
|
|
|
debug {
|
|
|
|
packagingOptions {
|
|
|
|
doNotStrip '**/*.so' // controlled by OpenCV CMake scripts
|
|
|
|
}
|
|
|
|
}
|
2018-02-18 06:36:15 +08:00
|
|
|
release {
|
2019-05-19 01:13:39 +08:00
|
|
|
packagingOptions {
|
|
|
|
doNotStrip '**/*.so' // controlled by OpenCV CMake scripts
|
|
|
|
}
|
2018-02-18 06:36:15 +08:00
|
|
|
minifyEnabled false
|
|
|
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-14 23:38:35 +08:00
|
|
|
buildFeatures {
|
|
|
|
prefabPublishing true
|
|
|
|
buildConfig true
|
|
|
|
}
|
|
|
|
prefab {
|
|
|
|
opencv_jni_shared {
|
|
|
|
headers "native/jni/include"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-18 06:36:15 +08:00
|
|
|
sourceSets {
|
|
|
|
main {
|
|
|
|
jniLibs.srcDirs = ['native/libs']
|
|
|
|
java.srcDirs = ['java/src']
|
|
|
|
res.srcDirs = ['java/res']
|
|
|
|
manifest.srcFile 'java/AndroidManifest.xml'
|
|
|
|
}
|
|
|
|
}
|
2019-07-12 04:04:05 +08:00
|
|
|
|
2023-12-14 23:38:35 +08:00
|
|
|
publishing {
|
|
|
|
singleVariant('release') {
|
|
|
|
withSourcesJar()
|
|
|
|
withJavadocJar()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 04:04:05 +08:00
|
|
|
externalNativeBuild {
|
|
|
|
cmake {
|
|
|
|
path (project.projectDir.toString() + '/libcxx_helper/CMakeLists.txt')
|
|
|
|
}
|
|
|
|
}
|
2018-02-18 06:36:15 +08:00
|
|
|
}
|
|
|
|
|
2023-12-14 23:38:35 +08:00
|
|
|
publishing {
|
|
|
|
publications {
|
|
|
|
release(MavenPublication) {
|
|
|
|
groupId = 'org.opencv'
|
|
|
|
artifactId = 'opencv'
|
|
|
|
version = '@OPENCV_VERSION_PLAIN@'
|
|
|
|
|
|
|
|
afterEvaluate {
|
|
|
|
from components.release
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
repositories {
|
|
|
|
maven {
|
|
|
|
name = 'myrepo'
|
|
|
|
url = "${project.buildDir}/repo"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-18 06:36:15 +08:00
|
|
|
dependencies {
|
|
|
|
}
|