summaryrefslogtreecommitdiff
path: root/android/source/build.gradle
blob: d3c4a1aabacdbef49727f4f509233a44b6d43032 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
project.ext.set("archivesBaseName", "LibreOfficeViewer")
//build-time dependencies - android plugin for gradle
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
    }
}

apply plugin: 'com.android.application'
// buildhost settings - paths and the like
apply from: 'liboSettings.gradle'

// compile-time dependencies
dependencies {
    compile fileTree(dir: "${liboInstdir}/${liboUREJavaFolder}", include: [
            "java_uno.jar",
            "juh.jar",
            "jurt.jar",
            "ridl.jar",
            "unoloader.jar"
    ])
    compile files("${liboInstdir}/${liboShareJavaFolder}/unoil.jar")
    compile files("${liboWorkdir}/UnpackedTarball/owncloud_android_lib/bin/owncloud-android-library.jar")
    compile 'com.android.support:appcompat-v7:23.0.1'
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    compileOptions {
        // silence some java-language features hints
        sourceCompatibility 6
    }
    // uses non-conventional source layout, so need to reconfigure accordingly
    // ToDo move to conventional layout, so stuff can be stripped down.
    sourceSets {
        main.manifest.srcFile 'AndroidManifest.xml'
        // override the debuggable flag that needs to be in AndroidManifest.xml
        // since ndk-gdb awks for the literal string in there :-/
        release.manifest.srcFile 'ReleaseManifest.xml'
        main.assets.srcDirs = ['assets']
        main.res.srcDirs = ['res']
        main.java.srcDirs = ['../Bootstrap/src', 'src/java']
        main.jniLibs.srcDirs = ['jniLibs']
        main.jni.srcDirs = [] // don't attempt to build native-lib via gradle
        // gdbserver for debugvariant
        debug.jniLibs.srcDirs "jniLibs_debug"
        // the configuration data that might be stripped or not
        fullUI.assets.srcDirs 'assets_fullUI'
        strippedUI.assets.srcDirs 'assets_strippedUI'
    }
    lintOptions {
        // ndk-gdb looks for the literal value in the pre-processed manifest :-(
        disable 'HardcodedDebugMode'
    }
    defaultConfig {
        minSdkVersion 14
        // openssl on x86 makes the native-code.so contain text-relocations,
        // 22 treats them as warnings, on 23 it is fatal error
        // ToDo: fix openssl stuff to not block targeting 23 or later
        targetSdkVersion 22
        manifestPlaceholders = [installLocation: "preferExternal"]
    }
    buildTypes {
        debug {
            // make android studio happy...
            jniDebuggable true
            // would work just fine with external, but setting emulator up is a little more work
            manifestPlaceholders = [installLocation: "internalOnly"]
        }
    }
    productFlavors {
        strippedUI
        fullUI
    }
}

/* remark inherited from makefile:
Then "assets". Let the directory structure under assets mimic
that under solver for now.

Please note that I have no idea what all of this is really necessary and for
much of this stuff being copied, no idea whether it makes any sense at all.
Much of this is copy-pasted from android/qa/sc/Makefile (where a couple of
unit tests for sc are built, and those do seem to mostly work) and
android/qa/desktop/Makefile (mmeeks's desktop demo, also works to some
extent)
 */

// Assets that are unpacked at run-time into the app's data directory. These
// are files read by non-LO code, fontconfig and freetype for now, that doesn't
// understand "/assets" paths.
task copyUnpackAssets(type: Copy) {
    description "copies assets that need to be extracted on the device"
    into 'assets/unpack'
    into('program') {
        from("${liboInstdir}/${liboEtcFolder}/types") {
            includes = [
                    "offapi.rdb",
                    "oovbaapi.rdb"
            ]
        }
        from("${liboInstdir}/${liboUreMiscFolder}") {
            includes = ["types.rdb"]
            rename 'types.rdb', 'udkapi.rdb'
        }
    }
    into('user/fonts') {
        from "${liboInstdir}/share/fonts/truetype"
        // Note: restrict list of fonts due to size considerations - no technical reason anymore
        // ToDo: fonts would be good candidate for using Expansion Files instead
        includes = [
                "Liberation*.ttf",
                "Caladea-*.ttf",
                "Carlito-*.ttf",
                "Gen*.ttf",
                "opens___.ttf"
        ]
    }
    into('etc/fonts') {
        from "./"
        includes = ['fonts.conf']
        filter {
            String line ->
                line.replaceAll(
                        '@@APPLICATION_ID@@', new String("${android.defaultConfig.applicationId}")
                )
        }
    }
}

task copyAssets(type: Copy) {
    description "copies assets that can be accessed within the installed apk"
    into 'assets'
    from("${liboSrcRoot}/readlicense_oo/license/") {
        includes = ["LICENSE", "NOTICE"]
        rename "LICENSE", "license.txt"
        rename "NOTICE", "notice.txt"
    }
    from("${liboExampleDocument}") {
        rename ".*", "example.odt"
    }
    into('program') {
        from "${liboInstdir}/program"
        includes = ['services.rdb', 'services/services.rdb']

        into('resource') {
            from "${liboInstdir}/${liboSharedResFolder}"
            includes = ['*en-US.res']
        }
    }
    into('share') {
        from "${liboInstdir}/share"
        // Filter data is needed by e.g. the drawingML preset shape import.
        includes = ['registry/**', 'filter/**']
        // those two get processed by mobile-config.py
        excludes = ['registry/main.xcd', 'registry/res/registry_en-US.xcd']
    }
}

task createFullConfig(type: Copy) {
    // grab dir to clear whole hierarchy on clean target
    outputs.dir "assets_fullUI"
    into 'assets_fullUI/share/config/soffice.cfg'
    from "${liboInstdir}/share/config/soffice.cfg"
}

task createStrippedConfig {
    def preserveDir = file("assets_strippedUI/share/config/soffice.cfg/empty")
    outputs.dir "assets_strippedUI"
    outputs.dir "assets_strippedUI/share/registry/res"
    outputs.file preserveDir

    doLast {
        file('assets_strippedUI/share/registry/res').mkdirs()
        file("assets_strippedUI/share/config/soffice.cfg").mkdirs()
        // just empty file
        preserveDir.text = ""
    }
}


task createStrippedConfigMain(type: Exec) {
    dependsOn 'createStrippedConfig'
    inputs.files "${liboInstdir}/share/registry/main.xcd", "${liboSrcRoot}/android/mobile-config.py"
    outputs.file "assets_strippedUI/share/registry/main.xcd"
    executable "${liboSrcRoot}/android/mobile-config.py"
    args = ["${liboInstdir}/share/registry/main.xcd", "assets_strippedUI/share/registry/main.xcd"]
}

task createStrippedConfigRegistry(type: Exec) {
    dependsOn 'createStrippedConfig'
    inputs.files "${liboInstdir}/share/registry/res/registry_en-US.xcd", "${liboSrcRoot}/android/mobile-config.py"
    outputs.file "assets_strippedUI/share/registry/res/registry_en-US.xcd"
    executable "${liboSrcRoot}/android/mobile-config.py"
    args = ["${liboInstdir}/share/registry/res/registry_en-US.xcd", "assets_strippedUI/share/registry/res/registry_en-US.xcd"]
    doFirst {
        file('assets_strippedUI/share/registry/res').mkdirs()
    }
}

// ndk-gdb requires the gdb.setup to be in libs/<arch>/ folder - it's hardcoded in the script
// it should in theory also be able to copy the gdbserver binary onto the device, but the matching
// against prebuilt archs is too rudimentary and doesn't map armeabi-v7 to arm for example
task copyNdkDebugServer(type: Copy) {
    description "copies gdbserver into and creates gdb.setup and Application.mk for use with ndk-gdb"
    inputs.file "liboSettings.gradle"
    def gdbsetup = file("libs/${liboAndroidAppAbi}/gdb.setup") // only needed on buildhost
    // hardcoded path from ndk-gdb - reads the host architecture from that file
    def applicationmk = file("jni/Application.mk")
    outputs.files gdbsetup, applicationmk
    outputs.dir 'jniLibs_debug' // own the directory, so it is removed on this task's clean
    outputs.dir 'libs' // own the directory, so it is removed on this task's clean
    into "jniLibs_debug/${liboAndroidAppAbi}"
    from "${liboNdkGdbserver}"
    doLast {
        file("libs/${liboAndroidAppAbi}").mkdirs()
        gdbsetup.text = "set solib-search-path ./obj/local/${liboAndroidAppAbi}\n"
        applicationmk.text = "APP_ABI := ${liboAndroidAppAbi}\n"
    }
}

task createRCfiles {
    inputs.file "liboSettings.gradle"
    dependsOn copyUnpackAssets, copyAssets
    def sofficerc     = file('assets/unpack/program/sofficerc')
    def fundamentalrc = file('assets/program/fundamentalrc')
    def bootstraprc   = file('assets/program/bootstraprc')
    def unorc         = file('assets/program/unorc')
    def versionrc     = file('assets/program/versionrc')

    outputs.files sofficerc, fundamentalrc, unorc, bootstraprc, versionrc

    doLast {
        sofficerc.text = '''\
            [Bootstrap]
            Logo=1
            NativeProgress=1
            URE_BOOTSTRAP=file:///assets/program/fundamentalrc
            HOME=$APP_DATA_DIR/cache
            OSL_SOCKET_PATH=$APP_DATA_DIR/cache
            '''.stripIndent()

        fundamentalrc.text =  '''\
            [Bootstrap]
            LO_LIB_DIR=file://$APP_DATA_DIR/lib/
            BRAND_BASE_DIR=file:///assets
            CONFIGURATION_LAYERS=xcsxcu:${BRAND_BASE_DIR}/share/registry res:${BRAND_BASE_DIR}/share/registry
            URE_BIN_DIR=file:///assets/ure/bin/dir/nothing-here/we-can/exec-anyway
            '''.stripIndent()

        bootstraprc.text =  '''\
            [Bootstrap]
            InstallMode=<installmode>
            ProductKey=LibreOffice '''+ "${liboVersionMajor}.${liboVersionMinor}" + '''
            UserInstallation=file://$APP_DATA_DIR
            '''.stripIndent()

        unorc.text = '''\
            [Bootstrap]
            URE_INTERNAL_LIB_DIR=file://$APP_DATA_DIR/lib/
            UNO_TYPES=file://$APP_DATA_DIR/program/udkapi.rdb file://$APP_DATA_DIR/program/offapi.rdb file://$APP_DATA_DIR/program/oovbaapi.rdb
            UNO_SERVICES=file:///assets/program/services.rdb file:///assets/program/services/services.rdb
            '''.stripIndent()

        versionrc.text = '''\
            [Version]
            AllLanguages=en-US
            BuildVersion=
            buildid=''' + "${liboGitFullCommit}" + '''
            ReferenceOOoMajorMinor=4.1
            '''.stripIndent()
    }
}

// creating the UI stuff is cheap, don't bother only applying it for the flavor..
preBuild.dependsOn 'createRCfiles',
        'createStrippedConfigMain',
        'createStrippedConfigRegistry',
        'createFullConfig',
        'copyNdkDebugServer'

clean.dependsOn 'cleanCopyAssets',
        'cleanCreateStrippedConfig',
        'cleanCreateFullConfig',
        'cleanCopyNdkDebugServer'