build.gradle.in 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. @KOTLIN_PLUGIN_DECLARATION@
  91. def openCVersionName = "@OPENCV_VERSION@"
  92. def openCVersionCode = ((@OPENCV_VERSION_MAJOR@ * 100 + @OPENCV_VERSION_MINOR@) * 100 + @OPENCV_VERSION_PATCH@) * 10 + 0
  93. println "OpenCV: " +openCVersionName + " " + project.buildscript.sourceFile
  94. android {
  95. compileSdkVersion @ANDROID_COMPILE_SDK_VERSION@
  96. defaultConfig {
  97. minSdkVersion @ANDROID_MIN_SDK_VERSION@
  98. targetSdkVersion @ANDROID_TARGET_SDK_VERSION@
  99. versionCode openCVersionCode
  100. versionName openCVersionName
  101. externalNativeBuild {
  102. cmake {
  103. arguments "-DANDROID_STL=@ANDROID_STL@"
  104. targets "opencv_jni_shared"
  105. }
  106. }
  107. }
  108. buildTypes {
  109. debug {
  110. packagingOptions {
  111. doNotStrip '**/*.so' // controlled by OpenCV CMake scripts
  112. }
  113. }
  114. release {
  115. packagingOptions {
  116. doNotStrip '**/*.so' // controlled by OpenCV CMake scripts
  117. }
  118. minifyEnabled false
  119. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
  120. }
  121. }
  122. sourceSets {
  123. main {
  124. jniLibs.srcDirs = ['native/libs']
  125. java.srcDirs = ['java/src']
  126. aidl.srcDirs = ['java/src']
  127. res.srcDirs = ['java/res']
  128. manifest.srcFile 'java/AndroidManifest.xml'
  129. }
  130. }
  131. externalNativeBuild {
  132. cmake {
  133. path (project.projectDir.toString() + '/libcxx_helper/CMakeLists.txt')
  134. }
  135. }
  136. }
  137. dependencies {
  138. }