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

apply plugin: 'com.android.library'

android {
6
    compileSdkVersion 28
7
8
9

    defaultConfig {
        minSdkVersion 11
10
        targetSdkVersion 28
11
12
13
        versionCode 321
        versionName "3.2.1"
        version "3.2.1"
14
15
16
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
17
18
19
20
21
22
        debug {
            resValue "string", "git_olm_revision", "\"${gitRevision()}\""
            resValue "string", "git_olm_revision_unix_date", "\"${gitRevisionUnixDate()}\""
            resValue "string", "git_olm_revision_date", "\"${gitRevisionDate()}\""
        }

23
        release {
24
25
26
27
            resValue "string", "git_olm_revision", "\"${gitRevision()}\""
            resValue "string", "git_olm_revision_unix_date", "\"${gitRevisionUnixDate()}\""
            resValue "string", "git_olm_revision_date", "\"${gitRevisionDate()}\""

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

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

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

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

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

pedroGitt's avatar
pedroGitt committed
62
63
64
65
66
67
68
69
    tasks.withType(JavaCompile) {
        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
        }
pedroGitt's avatar
pedroGitt committed
70
        compileTask.dependsOn buildJavaDoc
71
72
73
    }

    clean.dependsOn cleanNative
74
75
76
77


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

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
}

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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()
}

119
dependencies {
Benoit Marty's avatar
Benoit Marty committed
120
121
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'junit:junit:4.12'
122
    androidTestImplementation 'com.android.support:support-annotations:28.0.0'
Benoit Marty's avatar
Benoit Marty committed
123
124
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
125
}