aboutsummaryrefslogtreecommitdiff
path: root/android/olm-sdk/build.gradle
blob: a48a9a2ac0cd371accabdbf00806a7ee0c876a89 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion '21.1.2'

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 21
        versionCode 221
        versionName "2.2.1"
        version "2.2.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        debug {
            resValue "string", "git_olm_revision", "\"${gitRevision()}\""
            resValue "string", "git_olm_revision_unix_date", "\"${gitRevisionUnixDate()}\""
            resValue "string", "git_olm_revision_date", "\"${gitRevisionDate()}\""
        }

        release {
            resValue "string", "git_olm_revision", "\"${gitRevision()}\""
            resValue "string", "git_olm_revision_unix_date", "\"${gitRevisionUnixDate()}\""
            resValue "string", "git_olm_revision_date", "\"${gitRevisionDate()}\""

            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets.main {
        jniLibs.srcDir 'src/main/libs'
        jni.srcDirs = []
    }

   task buildJavaDoc(type: Javadoc) {
        source = android.sourceSets.main.java.srcDirs
        classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
        destinationDir = file("./doc/")
        options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PRIVATE
        failOnError false
    }

    task ndkBuildNativeRelease(type: Exec, description: 'NDK building..') {
        println 'ndkBuildNativeRelease starts..'
        workingDir file('src/main')
        commandLine getNdkBuildCmd(), 'NDK_DEBUG=0'
    }

    task ndkBuildNativeDebug(type: Exec, description: 'NDK building..') {
        println 'ndkBuildNativeDebug starts..'
        workingDir file('src/main')
        commandLine getNdkBuildCmd(), 'NDK_DEBUG=1'
    }

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

    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
        }
        compileTask.dependsOn buildJavaDoc
    }

    clean.dependsOn cleanNative


    libraryVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.aar')) {
                def fileName = outputFile.name.replace(".aar", "-${version}.aar")
                output.outputFile = new File(outputFile.parent, fileName)
            }
        }
    }
}

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
}

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()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.+'

    testCompile 'junit:junit:4.12'
    androidTestCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support:support-annotations:21.0.0'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test:rules:0.5'
}