build.gradle 3.88 KB
Newer Older
1
2
3
4
5
import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.library'

android {
6
    compileSdkVersion 30
7
8
9

    defaultConfig {
        minSdkVersion 11
10
        targetSdkVersion 30
11
12
13
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
14
15
16
17
18
19
        debug {
            resValue "string", "git_olm_revision", "\"${gitRevision()}\""
            resValue "string", "git_olm_revision_unix_date", "\"${gitRevisionUnixDate()}\""
            resValue "string", "git_olm_revision_date", "\"${gitRevisionDate()}\""
        }

20
        release {
21
22
23
24
            resValue "string", "git_olm_revision", "\"${gitRevision()}\""
            resValue "string", "git_olm_revision_unix_date", "\"${gitRevisionUnixDate()}\""
            resValue "string", "git_olm_revision_date", "\"${gitRevisionDate()}\""

25
26
27
28
29
30
31
32
33
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets.main {
        jniLibs.srcDir 'src/main/libs'
        jni.srcDirs = []
    }

34
    task buildJavaDoc(type: Javadoc) {
pedroGitt's avatar
pedroGitt committed
35
36
37
        source = android.sourceSets.main.java.srcDirs
        classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
        destinationDir = file("./doc/")
pedroGitt's avatar
pedroGitt committed
38
        options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PRIVATE
pedroGitt's avatar
pedroGitt committed
39
40
41
        failOnError false
    }

pedroGitt's avatar
pedroGitt committed
42
43
    task ndkBuildNativeRelease(type: Exec, description: 'NDK building..') {
        println 'ndkBuildNativeRelease starts..'
44
        workingDir file('src/main')
pedroGitt's avatar
pedroGitt committed
45
46
47
48
49
50
51
        commandLine getNdkBuildCmd(), 'NDK_DEBUG=0'
    }

    task ndkBuildNativeDebug(type: Exec, description: 'NDK building..') {
        println 'ndkBuildNativeDebug starts..'
        workingDir file('src/main')
        commandLine getNdkBuildCmd(), 'NDK_DEBUG=1'
52
53
54
55
56
57
58
    }

    task cleanNative(type: Exec, description: 'Clean NDK build') {
        workingDir file('src/main')
        commandLine getNdkBuildCmd(), 'clean'
    }

pedroGitt's avatar
pedroGitt committed
59
    tasks.withType(JavaCompile) {
60
61
62
63
64
65
66
67
68
        compileTask ->
            if (compileTask.name.startsWith('compileDebugJava')) {
                println 'test compile: Debug'
                compileTask.dependsOn ndkBuildNativeDebug
            } else if (compileTask.name.startsWith('compileReleaseJava')) {
                println 'test compile: Release'
                compileTask.dependsOn ndkBuildNativeRelease
            }
            compileTask.dependsOn buildJavaDoc
69
70
71
    }

    clean.dependsOn cleanNative
72
73
74
75


    libraryVariants.all { variant ->
        variant.outputs.each { output ->
Benoit Marty's avatar
Benoit Marty committed
76
77
78
            def outputFile = output.outputFileName
            if (outputFile != null && outputFile.endsWith('.aar')) {
                output.outputFileName = outputFile.replace(".aar", "-${version}.aar")
79
80
81
            }
        }
    }
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
}

def getNdkFolder() {
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    def ndkFolder = properties.getProperty('ndk.dir', null)
    if (ndkFolder == null)
        throw new GradleException("NDK location missing. Define it with ndk.dir in the local.properties file")

    return ndkFolder
}

def getNdkBuildCmd() {
    def ndkBuildCmd = getNdkFolder() + "/ndk-build"
    if (Os.isFamily(Os.FAMILY_WINDOWS))
        ndkBuildCmd += ".cmd"

    return ndkBuildCmd
}

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
def gitRevision() {
    def cmd = "git rev-parse --short HEAD"
    return cmd.execute().text.trim()
}

def gitRevisionUnixDate() {
    def cmd = "git show -s --format=%ct HEAD^{commit}"
    return cmd.execute().text.trim()
}

def gitRevisionDate() {
    def cmd = "git show -s --format=%ci HEAD^{commit}"
    return cmd.execute().text.trim()
}

117
dependencies {
118
119
120
121
122
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'junit:junit:4.13.2'

    androidTestImplementation 'androidx.test:runner:1.3.0'
    androidTestImplementation 'androidx.test:rules:1.3.0'
123
}