build.gradle.in 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 @OPENCV_VERSION_MAJOR@.@OPENCV_VERSION_MINOR@ 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. @MAVEN_PUBLISH_PLUGIN_DECLARATION@
  91. try {
  92. @KOTLIN_PLUGIN_DECLARATION@
  93. println "Configure OpenCV with Kotlin"
  94. } catch (Exception e) {
  95. println "Configure OpenCV without Kotlin"
  96. }
  97. def openCVersionName = "@OPENCV_VERSION@"
  98. def openCVersionCode = ((@OPENCV_VERSION_MAJOR@ * 100 + @OPENCV_VERSION_MINOR@) * 100 + @OPENCV_VERSION_PATCH@) * 10 + 0
  99. println "OpenCV: " +openCVersionName + " " + project.buildscript.sourceFile
  100. android {
  101. @OPENCV_ANDROID_NAMESPACE_DECLARATION@
  102. compileSdkVersion @ANDROID_COMPILE_SDK_VERSION@
  103. defaultConfig {
  104. minSdkVersion @ANDROID_MIN_SDK_VERSION@
  105. targetSdkVersion @ANDROID_TARGET_SDK_VERSION@
  106. versionCode openCVersionCode
  107. versionName openCVersionName
  108. externalNativeBuild {
  109. cmake {
  110. arguments "-DANDROID_STL=@ANDROID_STL@"
  111. targets "opencv_jni_shared"
  112. }
  113. }
  114. }
  115. @BUILD_GRADLE_COMPILE_OPTIONS@
  116. buildTypes {
  117. debug {
  118. packagingOptions {
  119. doNotStrip '**/*.so' // controlled by OpenCV CMake scripts
  120. }
  121. }
  122. release {
  123. packagingOptions {
  124. doNotStrip '**/*.so' // controlled by OpenCV CMake scripts
  125. }
  126. minifyEnabled false
  127. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
  128. }
  129. }
  130. sourceSets {
  131. main {
  132. jniLibs.srcDirs = [@SOURSE_SETS_JNI_LIBS_SRC_DIRS@]
  133. java.srcDirs = [@SOURSE_SETS_JAVA_SRC_DIRS@]
  134. res.srcDirs = [@SOURSE_SETS_RES_SRC_DIRS@]
  135. manifest.srcFile @SOURSE_SETS_MANIFEST_SRC_FILE@
  136. }
  137. }
  138. externalNativeBuild {
  139. cmake {
  140. path (project.projectDir.toString() + '/libcxx_helper/CMakeLists.txt')
  141. }
  142. }
  143. @BUILD_GRADLE_ANDROID_PUBLISHING_CONFIG@
  144. }
  145. @BUILD_GRADLE_PUBLISHING_CONFIG@
  146. dependencies {
  147. }