build.gradle 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import java.security.MessageDigest
  2. apply plugin: 'com.android.application'
  3. android {
  4. compileSdkVersion 29
  5. defaultConfig {
  6. applicationId "com.baidu.paddle.lite.demo.ocr"
  7. minSdkVersion 23
  8. targetSdkVersion 29
  9. versionCode 2
  10. versionName "2.0"
  11. testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  12. externalNativeBuild {
  13. cmake {
  14. cppFlags "-std=c++11 -frtti -fexceptions -Wno-format"
  15. arguments '-DANDROID_PLATFORM=android-23', '-DANDROID_STL=c++_shared' ,"-DANDROID_ARM_NEON=TRUE"
  16. }
  17. }
  18. }
  19. buildTypes {
  20. release {
  21. minifyEnabled false
  22. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  23. }
  24. }
  25. externalNativeBuild {
  26. cmake {
  27. path "src/main/cpp/CMakeLists.txt"
  28. version "3.10.2"
  29. }
  30. }
  31. }
  32. dependencies {
  33. implementation fileTree(include: ['*.jar'], dir: 'libs')
  34. implementation 'androidx.appcompat:appcompat:1.1.0'
  35. implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  36. testImplementation 'junit:junit:4.12'
  37. androidTestImplementation 'com.android.support.test:runner:1.0.2'
  38. androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
  39. }
  40. def archives = [
  41. [
  42. 'src' : 'https://paddleocr.bj.bcebos.com/libs/paddle_lite_libs_v2_10.tar.gz',
  43. 'dest': 'PaddleLite'
  44. ],
  45. [
  46. 'src' : 'https://paddlelite-demo.bj.bcebos.com/libs/android/opencv-4.2.0-android-sdk.tar.gz',
  47. 'dest': 'OpenCV'
  48. ],
  49. [
  50. 'src' : 'https://paddleocr.bj.bcebos.com/PP-OCRv2/lite/ch_PP-OCRv2.tar.gz',
  51. 'dest' : 'src/main/assets/models'
  52. ],
  53. [
  54. 'src' : 'https://paddleocr.bj.bcebos.com/dygraph_v2.0/lite/ch_dict.tar.gz',
  55. 'dest' : 'src/main/assets/labels'
  56. ]
  57. ]
  58. task downloadAndExtractArchives(type: DefaultTask) {
  59. doFirst {
  60. println "Downloading and extracting archives including libs and models"
  61. }
  62. doLast {
  63. // Prepare cache folder for archives
  64. String cachePath = "cache"
  65. if (!file("${cachePath}").exists()) {
  66. mkdir "${cachePath}"
  67. }
  68. archives.eachWithIndex { archive, index ->
  69. MessageDigest messageDigest = MessageDigest.getInstance('MD5')
  70. messageDigest.update(archive.src.bytes)
  71. String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
  72. // Download the target archive if not exists
  73. boolean copyFiles = !file("${archive.dest}").exists()
  74. if (!file("${cachePath}/${cacheName}.tar.gz").exists()) {
  75. ant.get(src: archive.src, dest: file("${cachePath}/${cacheName}.tar.gz"))
  76. copyFiles = true; // force to copy files from the latest archive files
  77. }
  78. // Extract the target archive if its dest path does not exists
  79. if (copyFiles) {
  80. copy {
  81. from tarTree("${cachePath}/${cacheName}.tar.gz")
  82. into "${archive.dest}"
  83. }
  84. }
  85. }
  86. }
  87. }
  88. preBuild.dependsOn downloadAndExtractArchives