build.gradle 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. // Notes about integration OpenCV into existed Android Studio application project are below (application 'app' module should exist).
  6. //
  7. // This file is located in <OpenCV-android-sdk>/sdk directory (near 'etc', 'java', 'native' subdirectories)
  8. //
  9. // Add module into Android Studio application project:
  10. //
  11. // - Android Studio way:
  12. // (will copy almost all OpenCV Android SDK into your project, ~200Mb)
  13. //
  14. // Import module: Menu -> "File" -> "New" -> "Module" -> "Import Gradle project":
  15. // Source directory: select this "sdk" directory
  16. // Module name: ":opencv"
  17. //
  18. // - or attach library module from OpenCV Android SDK
  19. // (without copying into application project directory, allow to share the same module between projects)
  20. //
  21. // Edit "settings.gradle" and add these lines:
  22. //
  23. // def opencvsdk='<path_to_opencv_android_sdk_rootdir>'
  24. // // You can put declaration above into gradle.properties file instead (including file in HOME directory),
  25. // // but without 'def' and apostrophe symbols ('): opencvsdk=<path_to_opencv_android_sdk_rootdir>
  26. // include ':opencv'
  27. // project(':opencv').projectDir = new File(opencvsdk + '/sdk')
  28. //
  29. //
  30. //
  31. // Add dependency into application module:
  32. //
  33. // - Android Studio way:
  34. // "Open Module Settings" (F4) -> "Dependencies" tab
  35. //
  36. // - or add "project(':opencv')" dependency into app/build.gradle:
  37. //
  38. // dependencies {
  39. // implementation fileTree(dir: 'libs', include: ['*.jar'])
  40. // ...
  41. // implementation project(':opencv')
  42. // }
  43. //
  44. //
  45. //
  46. // Load OpenCV native library before using:
  47. //
  48. // - avoid using of "OpenCVLoader.initAsync()" approach - it is deprecated
  49. // It may load library with different version (from OpenCV Android Manager, which is installed separatelly on device)
  50. //
  51. // - use "System.loadLibrary("opencv_java4")" or "OpenCVLoader.initDebug()"
  52. // TODO: Add accurate API to load OpenCV native library
  53. //
  54. //
  55. //
  56. // Native C++ support (necessary to use OpenCV in native code of application only):
  57. //
  58. // - Use find_package() in app/CMakeLists.txt:
  59. //
  60. // find_package(OpenCV 4.10 REQUIRED java)
  61. // ...
  62. // target_link_libraries(native-lib ${OpenCV_LIBRARIES})
  63. //
  64. // - Add "OpenCV_DIR" and enable C++ exceptions/RTTI support via app/build.gradle
  65. // Documentation about CMake options: https://developer.android.com/ndk/guides/cmake.html
  66. //
  67. // defaultConfig {
  68. // ...
  69. // externalNativeBuild {
  70. // cmake {
  71. // cppFlags "-std=c++11 -frtti -fexceptions"
  72. // arguments "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni" // , "-DANDROID_ARM_NEON=TRUE"
  73. // }
  74. // }
  75. // }
  76. //
  77. // - (optional) Limit/filter ABIs to build ('android' scope of 'app/build.gradle'):
  78. // Useful information: https://developer.android.com/studio/build/gradle-tips.html (Configure separate APKs per ABI)
  79. //
  80. // splits {
  81. // abi {
  82. // enable true
  83. // universalApk false
  84. // reset()
  85. // include 'armeabi-v7a' // , 'x86', 'x86_64', 'arm64-v8a'
  86. // }
  87. // }
  88. //
  89. apply plugin: 'com.android.library'
  90. apply plugin: 'maven-publish'
  91. apply plugin: 'kotlin-android'
  92. def openCVersionName = "4.10.0"
  93. def openCVersionCode = ((4 * 100 + 10) * 100 + 0) * 10 + 0
  94. println "OpenCV: " +openCVersionName + " " + project.buildscript.sourceFile
  95. android {
  96. namespace 'org.opencv'
  97. compileSdkVersion 31
  98. defaultConfig {
  99. minSdkVersion 21
  100. targetSdkVersion 31
  101. versionCode openCVersionCode
  102. versionName openCVersionName
  103. externalNativeBuild {
  104. cmake {
  105. arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_PLATFORM=android-21","-DANDROID_STL=c++_shared"
  106. targets "opencv_jni_shared"
  107. }
  108. }
  109. ndk {
  110. abiFilters "armeabi-v7a"/*, "arm64-v8a", "x86"*/
  111. }
  112. }
  113. compileOptions {
  114. sourceCompatibility JavaVersion.VERSION_17
  115. targetCompatibility JavaVersion.VERSION_17
  116. }
  117. buildTypes {
  118. debug {
  119. packagingOptions {
  120. doNotStrip '**/*.so' // controlled by OpenCV CMake scripts
  121. }
  122. }
  123. release {
  124. packagingOptions {
  125. doNotStrip '**/*.so' // controlled by OpenCV CMake scripts
  126. }
  127. minifyEnabled false
  128. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
  129. }
  130. }
  131. buildFeatures {
  132. prefabPublishing true
  133. buildConfig true
  134. }
  135. prefab {
  136. opencv_jni_shared {
  137. headers "native/jni/include"
  138. }
  139. }
  140. sourceSets {
  141. main {
  142. jniLibs.srcDirs = ['native/libs']
  143. java.srcDirs = ['java/src']
  144. res.srcDirs = ['java/res']
  145. manifest.srcFile 'java/AndroidManifest.xml'
  146. }
  147. }
  148. publishing {
  149. singleVariant('release') {
  150. withSourcesJar()
  151. withJavadocJar()
  152. }
  153. }
  154. externalNativeBuild {
  155. cmake {
  156. path (project.projectDir.toString() + '/libcxx_helper/CMakeLists.txt')
  157. }
  158. }
  159. }
  160. publishing {
  161. publications {
  162. release(MavenPublication) {
  163. groupId = 'org.opencv'
  164. artifactId = 'opencv'
  165. version = '4.10.0'
  166. afterEvaluate {
  167. from components.release
  168. }
  169. }
  170. }
  171. repositories {
  172. maven {
  173. name = 'myrepo'
  174. url = "${project.buildDir}/repo"
  175. }
  176. }
  177. }
  178. dependencies {
  179. }