build.gradle 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import java.security.MessageDigest
  2. apply plugin: 'com.android.application'
  3. android {
  4. compileSdkVersion 30
  5. buildToolsVersion "30.0.2"
  6. defaultConfig {
  7. applicationId "com.baidu.paddledetection.detection"
  8. minSdkVersion 23
  9. targetSdkVersion 30
  10. versionCode 1
  11. versionName "1.0"
  12. testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  13. externalNativeBuild {
  14. cmake {
  15. arguments '-DANDROID_PLATFORM=android-23', '-DANDROID_STL=c++_shared', "-DANDROID_TOOLCHAIN="
  16. abiFilters 'arm64-v8a'
  17. cppFlags "-std=c++11"
  18. }
  19. }
  20. }
  21. buildTypes {
  22. release {
  23. minifyEnabled false
  24. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  25. }
  26. }
  27. externalNativeBuild {
  28. cmake {
  29. path "src/main/cpp/CMakeLists.txt"
  30. version "3.10.2"
  31. }
  32. }
  33. }
  34. dependencies {
  35. implementation fileTree(dir: "libs", include: ["*.jar"])
  36. implementation 'androidx.appcompat:appcompat:1.1.0'
  37. implementation 'com.google.android.material:material:1.0.0'
  38. implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  39. implementation 'androidx.navigation:navigation-fragment:2.1.0'
  40. implementation 'androidx.navigation:navigation-ui:2.1.0'
  41. testImplementation 'junit:junit:4.12'
  42. androidTestImplementation 'androidx.test.ext:junit:1.1.1'
  43. androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  44. }
  45. def archives = [
  46. [
  47. 'src' : 'https://paddlelite-demo.bj.bcebos.com/libs/android/paddle_lite_libs_v2_6_1.tar.gz',
  48. 'dest': 'PaddleLite'
  49. ],
  50. [
  51. 'src' : 'https://paddlelite-demo.bj.bcebos.com/libs/android/opencv-4.2.0-android-sdk.tar.gz',
  52. 'dest': 'OpenCV'
  53. ],
  54. // yolov3_mobilenet_v3
  55. [
  56. 'src' : 'https://paddlelite-demo.bj.bcebos.com/models/yolov3_mobilenet_v3_prune86_FPGM_320_fp32_for_cpu_v2_6_1.tar.gz',
  57. 'dest' : 'src/main/assets/models/yolov3_mobilenet_v3_for_cpu'
  58. ],
  59. [
  60. 'src' : 'https://paddlelite-demo.bj.bcebos.com/models/yolov3_mobilenet_v3_prune86_FPGM_320_fp32_for_hybrid_cpu_npu_v2_6_1.tar.gz',
  61. 'dest' : 'src/main/assets/models/yolov3_mobilenet_v3_for_hybrid_cpu_npu'
  62. ],
  63. // pp-yolo tiny coming soon
  64. // ssd_mobilenet_v1 voc
  65. [
  66. 'src' : 'https://paddlelite-demo.bj.bcebos.com/models/ssdlite_mobilenet_v3_large_for_cpu_nb.tar.gz',
  67. 'dest' : 'src/main/assets/models/ssdlite_mobilenet_v3_large_for_cpu_nb'
  68. ],
  69. ]
  70. task downloadAndExtractArchives(type: DefaultTask) {
  71. doFirst {
  72. println "Downloading and extracting archives including libs and models"
  73. }
  74. doLast {
  75. // Prepare cache folder for archives
  76. String cachePath = "cache"
  77. if (!file("${cachePath}").exists()) {
  78. mkdir "${cachePath}"
  79. }
  80. archives.eachWithIndex { archive, index ->
  81. MessageDigest messageDigest = MessageDigest.getInstance('MD5')
  82. messageDigest.update(archive.src.bytes)
  83. String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
  84. // Download the target archive if not exists
  85. boolean copyFiles = !file("${archive.dest}").exists()
  86. if (!file("${cachePath}/${cacheName}.tar.gz").exists()) {
  87. ant.get(src: archive.src, dest: file("${cachePath}/${cacheName}.tar.gz"))
  88. copyFiles = true; // force to copy files from the latest archive files
  89. }
  90. // Extract the target archive if its dest path does not exists
  91. if (copyFiles) {
  92. copy {
  93. from tarTree("${cachePath}/${cacheName}.tar.gz")
  94. into "${archive.dest}"
  95. }
  96. }
  97. // Unpack libs
  98. copy {
  99. from tarTree("cache/${cacheName}.tar.gz")
  100. into "cache/${cacheName}"
  101. }
  102. // Copy PaddlePredictor.jar
  103. if (!file("libs/PaddlePredictor.jar").exists()) {
  104. copy {
  105. from "cache/${cacheName}/java/PaddlePredictor.jar"
  106. into "libs"
  107. }
  108. }
  109. // Copy libpaddle_lite_jni.so for armeabi-v7a and arm64-v8a
  110. if (!file("src/main/jniLibs/armeabi-v7a/libpaddle_lite_jni.so").exists()) {
  111. copy {
  112. from "cache/${cacheName}/java/libs/armeabi-v7a/libpaddle_lite_jni.so"
  113. into "src/main/jniLibs/armeabi-v7a"
  114. }
  115. }
  116. if (!file("src/main/jniLibs/arm64-v8a/libpaddle_lite_jni.so").exists()) {
  117. copy {
  118. from "cache/${cacheName}/java/libs/arm64-v8a/libpaddle_lite_jni.so"
  119. into "src/main/jniLibs/arm64-v8a"
  120. }
  121. }
  122. }
  123. }
  124. }
  125. preBuild.dependsOn downloadAndExtractArchives