build.gradle 5.72 KB
Newer Older
1
2
3
// Copyright 2020, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0

4
5
6
plugins {
    id 'com.android.application'
    id 'kotlin-android'
7

8
9
    id 'com.mikepenz.aboutlibraries.plugin'

10
11
12
13
14
15
    // Hilt dependency injection
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'

    // SVG files in the "raw" resource directory will be transformed into vector drawables of the same name.
    id 'com.quittle.svg-2-android-vector'
16
}
17

18
19
androidGitVersion {
    tagPattern(/^v[0-9]+.*/)
20
    codeFormat = 'MMNNPPBBB'
21
    format = '%tag%%-count%%-gcommit%%-dirty%'
22
}
23
24

def parseOpenXRVersion(def fn) {
25
26
    def matches = file(fn).readLines().find {
        it.contains('XR_CURRENT_API_VERSION')
27
    } =~ ~/XR_MAKE_VERSION\(([^)]+)\)/
28
29
30
31
    def components = matches[0][1].split(',').each { it.replace(' ', '').trim() }
    String.join('.', components)
}

32
33
34
35
36
37
38
39
40
41
42
43
44
project.ext.renameLicense = { String name ->
    def lowerNoExtension = name.toLowerCase().replace(".txt", "")
    def result = lowerNoExtension.replaceAll(~/[\-.]/, "_") + ".txt"
    return result
}

project.ext.filterLicense = {String line ->
    if (line.trim().isEmpty()) {
        return '<br /><br />'
    } else {
        return groovy.xml.XmlUtil.escapeXml(line)
    }
}
45
46
47
48
49

// TODO: this copies to the source dir for simplicity right now, but it's not great!
task copyLicenses(type: Copy) {
    from "${rootDir}/LICENSES/"
    include 'BSL-1.0.txt'
50
    rename(renameLicense)
51
    into project.layout.projectDirectory.dir('src/main/res/raw').asFile
52
    filter(filterLicense)
53
}
54
project.ext.licenseDir = new File(project.buildDir, 'intermediates/licenses/')
55

56
// For JSR250 used by Hilt
57
58
59
60
61
62
63
64
65
66
67
68
69
task downloadCddl(type: Download) {
    src 'https://spdx.org/licenses/CDDL-1.0.txt'
    dest "${project.licenseDir}/CDDL-1.0.txt"
    overwrite false
}

task copyDownloadedLicenses(type: Copy) {
    from downloadCddl.dest
    rename(renameLicense)
    into project.layout.projectDirectory.dir('src/main/res/raw').asFile
    filter(filterLicense)
    dependsOn downloadCddl
}
70
71
72
73
74
75
76
77
78
79
android {
    compileSdkVersion project.sharedTargetSdk
    buildToolsVersion '30.0.2'

    ndkVersion "${ndk_version}"

    defaultConfig {
        applicationId 'org.freedesktop.monado.openxr_runtime'
        minSdkVersion project.sharedMinSdk
        targetSdkVersion project.sharedTargetSdk
80
81
82

        versionCode androidGitVersion.code()
        versionName androidGitVersion.name()
83

84
85
        println versionName

86
        resValue "string", "monado_lib_version", "${versionName}"
87

88
        resValue "string", "library_openxrheaders_libraryVersion", parseOpenXRVersion("${rootDir}/src/external/openxr_includes/openxr/openxr.h")
89

90
91
        externalNativeBuild {
            cmake {
92
                arguments "-DEIGEN3_INCLUDE_DIR=${project.eigenIncludeDir}", "-DANDROID_PLATFORM=26", "-DANDROID_STL=c++_shared", "-DANDROID_ARM_NEON=TRUE"
93
94
95

            }
            if (project.pythonBinary != null) {
96
                println "Path to Python 3 explicitly specified: ${project.pythonBinary}"
97
                cmake.arguments "-DPYTHON_EXECUTABLE=${project.pythonBinary}"
98
99
            }
        }
100
101
102

        // Be sure to copy over licenses formatted as required.
        preBuild.dependsOn(copyLicenses)
103
        preBuild.dependsOn(copyDownloadedLicenses)
104
105
106
107
108
    }

    buildTypes {
        release {
            minifyEnabled false
109
110
            // Gradle plugin produces proguard-android-optimize.txt from @Keep annotations
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
111
112
113
114
115
        }
    }

    externalNativeBuild {
        cmake {
116
            path "${rootDir}/CMakeLists.txt"
117
118
119
        }
    }

120
121
122
123
    lintOptions {
        fatal 'StopShip'
    }

124
125
126
127
128
129
130
    flavorDimensions 'deployment'
    productFlavors {
        inProcess {
            dimension 'deployment'
            applicationIdSuffix '.in_process'
            externalNativeBuild.cmake.arguments += "-DXRT_FEATURE_SERVICE=OFF"
            externalNativeBuild.cmake.targets "openxr_monado"
131
132

            resValue "string", "app_name", "Monado XR"
133
134
135
136
137
138
        }
        outOfProcess {
            dimension 'deployment'
            applicationIdSuffix '.out_of_process'
            externalNativeBuild.cmake.arguments += "-DXRT_FEATURE_SERVICE=ON"
            externalNativeBuild.cmake.targets "openxr_monado", "monado-service"
139
140

            resValue "string", "app_name", "Monado XR (Out-of-Proc)"
141
142
143
144
145
146
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
147
148
149
    packagingOptions {
        exclude("META-INF/*.kotlin_module")
    }
150

151
152
}

153
aboutLibraries {
154
    configPath = "${projectDir}/config"
155
156
157
158
159
160
161

    // Full license text for license IDs mentioned here
    // will be included, even if no detected dependency uses them.
    additionalLicenses {
        mit
        mpl_2_0
    }
162
163
}

164
dependencies {
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
165
    outOfProcessImplementation project(':src:xrt:ipc:android')
166
    implementation project(':src:xrt:auxiliary:android')
167
    implementation project(':src:xrt:targets:android_common')
168
169
170
171
172
173
    implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
    implementation "androidx.constraintlayout:constraintlayout:$androidxConstraintLayoutVersion"
    implementation "com.google.android.material:material:$materialVersion"

    // Dependencies related only to AboutLibraries
174
175
    implementation "com.mikepenz:aboutlibraries-core:${latestAboutLibsRelease}"
    implementation "com.mikepenz:aboutlibraries:${latestAboutLibsRelease}"
176
177
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.2.0'
178

179
180
181
182
183

    // for Hilt dependency injection
    implementation "com.google.dagger:hilt-android:$hiltVersion"
    kapt "com.google.dagger:hilt-compiler:$hiltVersion"

184
}