|
| 1 | +// This file is part of OpenCV project. |
| 2 | +// It is subject to the license terms in the LICENSE file found in the top-level directory |
| 3 | +// of this distribution and at http://opencv.org/license.html. |
| 4 | + |
| 5 | +// |
| 6 | +// Notes about integration OpenCV into existed Android Studio application project are below (application 'app' module should exist). |
| 7 | +// |
| 8 | +// This file is located in <OpenCV-android-sdk>/sdk directory (near 'etc', 'java', 'native' subdirectories) |
| 9 | +// |
| 10 | +// Add module into Android Studio application project: |
| 11 | +// |
| 12 | +// - Android Studio way: |
| 13 | +// (will copy almost all OpenCV Android SDK into your project, ~200Mb) |
| 14 | +// |
| 15 | +// Import module: Menu -> "File" -> "New" -> "Module" -> "Import Gradle project": |
| 16 | +// Source directory: select this "sdk" directory |
| 17 | +// Module name: ":opencv" |
| 18 | +// |
| 19 | +// - or attach library module from OpenCV Android SDK |
| 20 | +// (without copying into application project directory, allow to share the same module between projects) |
| 21 | +// |
| 22 | +// Edit "settings.gradle" and add these lines: |
| 23 | +// |
| 24 | +// def opencvsdk='<path_to_opencv_android_sdk_rootdir>' |
| 25 | +// // You can put declaration above into gradle.properties file instead (including file in HOME directory), |
| 26 | +// // but without 'def' and apostrophe symbols ('): opencvsdk=<path_to_opencv_android_sdk_rootdir> |
| 27 | +// include ':opencv' |
| 28 | +// project(':opencv').projectDir = new File(opencvsdk + '/sdk') |
| 29 | +// |
| 30 | +// |
| 31 | +// |
| 32 | +// Add dependency into application module: |
| 33 | +// |
| 34 | +// - Android Studio way: |
| 35 | +// "Open Module Settings" (F4) -> "Dependencies" tab |
| 36 | +// |
| 37 | +// - or add "project(':opencv')" dependency into app/build.gradle: |
| 38 | +// |
| 39 | +// dependencies { |
| 40 | +// implementation fileTree(dir: 'libs', include: ['*.jar']) |
| 41 | +// ... |
| 42 | +// implementation project(':opencv') |
| 43 | +// } |
| 44 | +// |
| 45 | +// |
| 46 | +// |
| 47 | +// Load OpenCV native library before using: |
| 48 | +// |
| 49 | +// - avoid using of "OpenCVLoader.initAsync()" approach - it is deprecated |
| 50 | +// It may load library with different version (from OpenCV Android Manager, which is installed separatelly on device) |
| 51 | +// |
| 52 | +// - use "System.loadLibrary("opencv_java3")" or "OpenCVLoader.initDebug()" |
| 53 | +// TODO: Add accurate API to load OpenCV native library |
| 54 | +// |
| 55 | +// |
| 56 | +// |
| 57 | +// Native C++ support (necessary to use OpenCV in native code of application only): |
| 58 | +// |
| 59 | +// - Use find_package() in app/CMakeLists.txt: |
| 60 | +// |
| 61 | +// find_package(OpenCV 3.4 REQUIRED java) |
| 62 | +// ... |
| 63 | +// target_link_libraries(native-lib ${OpenCV_LIBRARIES}) |
| 64 | +// |
| 65 | +// - Add "OpenCV_DIR" and enable C++ exceptions/RTTI support via app/build.gradle |
| 66 | +// Documentation about CMake options: https://developer.android.com/ndk/guides/cmake.html |
| 67 | +// |
| 68 | +// defaultConfig { |
| 69 | +// ... |
| 70 | +// externalNativeBuild { |
| 71 | +// cmake { |
| 72 | +// cppFlags "-std=c++11 -frtti -fexceptions" |
| 73 | +// arguments "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni" // , "-DANDROID_ARM_NEON=TRUE" |
| 74 | +// } |
| 75 | +// } |
| 76 | +// } |
| 77 | +// |
| 78 | +// - (optional) Limit/filter ABIs to build ('android' scope of 'app/build.gradle'): |
| 79 | +// Useful information: https://developer.android.com/studio/build/gradle-tips.html (Configure separate APKs per ABI) |
| 80 | +// |
| 81 | +// splits { |
| 82 | +// abi { |
| 83 | +// enable true |
| 84 | +// reset() |
| 85 | +// include 'armeabi-v7a' // , 'x86', 'x86_64', 'arm64-v8a' |
| 86 | +// universalApk false |
| 87 | +// } |
| 88 | +// } |
| 89 | +// |
| 90 | + |
| 91 | +apply plugin: 'com.android.library' |
| 92 | + |
| 93 | +println "OpenCV: " + project.buildscript.sourceFile |
| 94 | + |
| 95 | +android { |
| 96 | + compileSdkVersion 27 |
| 97 | + //buildToolsVersion "27.0.3" // not needed since com.android.tools.build:gradle:3.0.0 |
| 98 | + |
| 99 | + defaultConfig { |
| 100 | + minSdkVersion 14 |
| 101 | + targetSdkVersion 21 |
| 102 | + } |
| 103 | + |
| 104 | + buildTypes { |
| 105 | + release { |
| 106 | + minifyEnabled false |
| 107 | + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' |
| 108 | + } |
| 109 | + } |
| 110 | + compileOptions { |
| 111 | + sourceCompatibility JavaVersion.VERSION_1_6 |
| 112 | + targetCompatibility JavaVersion.VERSION_1_6 |
| 113 | + } |
| 114 | + |
| 115 | + sourceSets { |
| 116 | + main { |
| 117 | + jniLibs.srcDirs = ['native/libs'] |
| 118 | + java.srcDirs = ['java/src'] |
| 119 | + aidl.srcDirs = ['java/src'] |
| 120 | + res.srcDirs = ['java/res'] |
| 121 | + manifest.srcFile 'java/AndroidManifest.xml' |
| 122 | + } |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +dependencies { |
| 127 | +} |
0 commit comments