build.gradle 3.44 KB
Newer Older
WenmuZhou's avatar
WenmuZhou committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.security.MessageDigest

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.baidu.paddle.lite.demo.ocr"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++11 -frtti -fexceptions -Wno-format"
                arguments '-DANDROID_PLATFORM=android-23', '-DANDROID_STL=c++_shared' ,"-DANDROID_ARM_NEON=TRUE"
            }
        }
        ndk {
            // abiFilters "arm64-v8a", "armeabi-v7a"
            abiFilters   "arm64-v8a", "armeabi-v7a"
            ldLibs "jnigraphics"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
            version "3.10.2"
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

def archives = [
        [
WenmuZhou's avatar
WenmuZhou committed
51
                'src' : 'https://paddleocr.bj.bcebos.com/dygraph_v2.0/lite/paddle_lite_libs_v2_8_0.gz',
WenmuZhou's avatar
WenmuZhou committed
52
53
54
55
56
57
58
                'dest': 'PaddleLite'
        ],
        [
                'src' : 'https://paddlelite-demo.bj.bcebos.com/libs/android/opencv-4.2.0-android-sdk.tar.gz',
                'dest': 'OpenCV'
        ],
        [
WenmuZhou's avatar
WenmuZhou committed
59
                'src' : 'https://paddleocr.bj.bcebos.com/dygraph_v2.0/lite/ocr_v2_for_cpu.tar.gz',
WenmuZhou's avatar
WenmuZhou committed
60
                'dest' : 'src/main/assets/models'
WenmuZhou's avatar
WenmuZhou committed
61
62
63
64
        ],
        [
                'src' : 'https://paddleocr.bj.bcebos.com/dygraph_v2.0/lite/ch_dict.tar.gz',
                'dest' : 'src/main/assets/labels'
WenmuZhou's avatar
WenmuZhou committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
        ]
]

task downloadAndExtractArchives(type: DefaultTask) {
    doFirst {
        println "Downloading and extracting archives including libs and models"
    }
    doLast {
        // Prepare cache folder for archives
        String cachePath = "cache"
        if (!file("${cachePath}").exists()) {
            mkdir "${cachePath}"
        }
        archives.eachWithIndex { archive, index ->
            MessageDigest messageDigest = MessageDigest.getInstance('MD5')
            messageDigest.update(archive.src.bytes)
            String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
            // Download the target archive if not exists
            boolean copyFiles = !file("${archive.dest}").exists()
            if (!file("${cachePath}/${cacheName}.tar.gz").exists()) {
                ant.get(src: archive.src, dest: file("${cachePath}/${cacheName}.tar.gz"))
                copyFiles = true; // force to copy files from the latest archive files
            }
            // Extract the target archive if its dest path does not exists
            if (copyFiles) {
                copy {
                    from tarTree("${cachePath}/${cacheName}.tar.gz")
                    into "${archive.dest}"
                }
            }
        }
    }
}
preBuild.dependsOn downloadAndExtractArchives