Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / android / source / build.gradle
blob32de09f847499eaebfdf1fe4ce5582ae9f5b6645
1 apply plugin: 'com.android.application'
2 // buildhost settings - paths and the like
3 apply from: 'liboSettings.gradle'
5 project.ext.set("archivesBaseName", "LibreOfficeViewer")
6 allprojects {
7     repositories {
8         jcenter()
9         google()
10         flatDir {
11             dirs "${liboWorkdir}/UnpackedTarball/owncloud_android_lib/build/outputs/aar"
12         }
13     }
15 //build-time dependencies - android plugin for gradle
16 buildscript {
17     repositories {
18         jcenter()
19         google()
20     }
21     dependencies {
22         classpath 'com.android.tools.build:gradle:3.6.1'
23     }
26 // compile-time dependencies
27 dependencies {
28     implementation fileTree(dir: "${liboInstdir}/${liboUREJavaFolder}", include: [
29             "java_uno.jar",
30             "libreoffice.jar",
31             "unoloader.jar"
32     ])
33     implementation(name:'owncloud_android_lib', ext:'aar')
34     implementation 'com.android.support:design:27.1.1' // also pulls-in corresponding support libraries
35     implementation 'com.android.support.constraint:constraint-layout:1.1.2'
38 android {
39     compileSdkVersion 28
40     compileOptions {
41         // silence some java-language features hints
42         sourceCompatibility 6
43     }
44     // uses non-conventional source layout, so need to reconfigure accordingly
45     // ToDo move to conventional layout, so stuff can be stripped down.
46     sourceSets {
47         main.manifest.srcFile 'AndroidManifest.xml'
48         main.assets.srcDirs = ['assets']
49         main.res.srcDirs = ['res']
50         main.java.srcDirs = ['../Bootstrap/src', 'src/java']
51         main.jniLibs.srcDirs = ["${liboJniLibsdir}"]
52         main.jni.srcDirs = [] // don't attempt to build native-lib via gradle
53         // the configuration data that might be stripped or not
54         fullUI.assets.srcDirs 'assets_fullUI'
55         strippedUI.assets.srcDirs 'assets_strippedUI'
56         strippedUIEditing.assets.srcDirs 'assets_strippedUI'
57     }
58     defaultConfig {
59         minSdkVersion 16
60         targetSdkVersion 28
61         vectorDrawables.useSupportLibrary = true
62     }
63     buildTypes {
64         debug {
65             // make android studio happy...
66             jniDebuggable true
67             // would work just fine with external, but setting emulator up is a little more work
68             manifestPlaceholders = [installLocation: "auto"]
69         }
70         release {
71             manifestPlaceholders = [installLocation: "preferExternal"]
72         }
73     }
75     flavorDimensions "default"
76     productFlavors {
77         strippedUI {
78             dimension "default"
79             buildConfigField 'boolean', 'ALLOW_EDITING', 'false'
80         }
81         strippedUIEditing {
82             dimension "default"
83             buildConfigField 'boolean', 'ALLOW_EDITING', 'true'
84             versionNameSuffix "-editing"
85         }
86         fullUI.dimension "default"
87     }
88     lintOptions {
89         // don't error-out on missing translations
90         warning 'MissingTranslation'
91     }
94 /* remark inherited from makefile:
95 Then "assets". Let the directory structure under assets mimic
96 that under solver for now.
98 Please note that I have no idea what all of this is really necessary and for
99 much of this stuff being copied, no idea whether it makes any sense at all.
100 Much of this is copy-pasted from android/qa/sc/Makefile (where a couple of
101 unit tests for sc are built, and those do seem to mostly work) and
102 android/qa/desktop/Makefile (mmeeks's desktop demo, also works to some
103 extent)
104  */
106 // Assets that are unpacked at run-time into the app's data directory. These
107 // are files read by non-LO code, fontconfig and freetype for now, that doesn't
108 // understand "/assets" paths.
109 task copyUnpackAssets(type: Copy) {
110     description "copies assets that need to be extracted on the device"
111     into 'assets/unpack'
112     into('program') {
113         from("${liboInstdir}/${liboEtcFolder}/types") {
114             includes = [
115                     "offapi.rdb",
116                     "oovbaapi.rdb"
117             ]
118         }
119         from("${liboInstdir}/${liboUreMiscFolder}") {
120             includes = ["types.rdb"]
121             rename 'types.rdb', 'udkapi.rdb'
122         }
123     }
124     into('user/fonts') {
125         from "${liboInstdir}/share/fonts/truetype"
126         // Note: restrict list of fonts due to size considerations - no technical reason anymore
127         // ToDo: fonts would be good candidate for using Expansion Files instead
128         includes = [
129                 "Liberation*.ttf",
130                 "Caladea-*.ttf",
131                 "Carlito-*.ttf",
132                 "Gen*.ttf",
133                 "opens___.ttf"
134         ]
135     }
136     into('etc/fonts') {
137         from "./"
138         includes = ['fonts.conf']
139         filter {
140             String line ->
141                 line.replaceAll(
142                         '@@APPLICATION_ID@@', new String("${android.defaultConfig.applicationId}")
143                 )
144         }
145     }
148 task copyAssets(type: Copy) {
149     description "copies assets that can be accessed within the installed apk"
150     into 'assets'
151     from("${liboInstdir}") {
152         includes = ["LICENSE", "NOTICE"]
153         rename "LICENSE", "license.txt"
154         rename "NOTICE", "notice.txt"
155     }
156     from("${liboExampleDocument}") {
157         rename ".*", "example.odt"
158     }
160     // include icons
161     into ('share') {
162         into ('config') {
163             from ("${liboInstdir}/share/config")
164             includes = ['images_**.zip']
165         }
166     }
168     into('program') {
169         from "${liboInstdir}/program"
170         includes = ['services.rdb', 'services/services.rdb']
172         into('resource') {
173             from "${liboInstdir}/${liboSharedResFolder}"
174             includes = ['*en-US.res']
175         }
176     }
177     into('share') {
178         from("${liboInstdir}/share") {
179             // Filter data is needed by e.g. the drawingML preset shape import.
180             includes = ['registry/**', 'filter/**']
181             // those two get processed by mobile-config.py
182             excludes = ['registry/main.xcd', 'registry/res/registry_en-US.xcd']
183         }
184         // separate data files for Chinese and Japanese
185         from("${liboWorkdir}/CustomTarget/i18npool/breakiterator/") {
186             include '*.data'
187         }
188     }
189     // documents with manual page break trigger attempt to read the ui file 'pagebreakmenu.ui'
190     // would trigger a css::container::NoSuchElementException with osl_File_E_NOENT
191     // if not present and since it is not caught would crash the app;
192     // 'annotationmenu.ui' required to handle documents containing comments,
193     // 'headerfootermenu.ui' when clicking inside header/footer of document
194     into('config') {
195         from "${liboInstdir}/share/config"
196         include '**/pagebreakmenu.ui', '**/annotationmenu.ui', '**/headerfootermenu.ui'
197     }
200 task createFullConfig(type: Copy) {
201     // grab dir to clear whole hierarchy on clean target
202     outputs.dir "assets_fullUI"
203     into 'assets_fullUI/share/config/soffice.cfg'
204     from "${liboInstdir}/share/config/soffice.cfg"
207 task createStrippedConfig {
208     def preserveDir = file("assets_strippedUI/share/config/soffice.cfg/empty")
209     outputs.dir "assets_strippedUI"
210     outputs.dir "assets_strippedUI/share/registry/res"
211     outputs.file preserveDir
213     doLast {
214         file('assets_strippedUI/share/registry/res').mkdirs()
215         file("assets_strippedUI/share/config/soffice.cfg").mkdirs()
216         // just empty file
217         preserveDir.text = ""
218     }
222 task createStrippedConfigMain(type: Exec) {
223     dependsOn 'createStrippedConfig'
224     inputs.files "${liboInstdir}/share/registry/main.xcd", "${liboSrcRoot}/android/mobile-config.py"
225     outputs.file "assets_strippedUI/share/registry/main.xcd"
226     executable "${liboSrcRoot}/android/mobile-config.py"
227     args = ["${liboInstdir}/share/registry/main.xcd", "assets_strippedUI/share/registry/main.xcd"]
230 task createStrippedConfigRegistry(type: Exec) {
231     dependsOn 'createStrippedConfig'
232     inputs.files "${liboInstdir}/share/registry/res/registry_en-US.xcd", "${liboSrcRoot}/android/mobile-config.py"
233     outputs.file "assets_strippedUI/share/registry/res/registry_en-US.xcd"
234     executable "${liboSrcRoot}/android/mobile-config.py"
235     args = ["${liboInstdir}/share/registry/res/registry_en-US.xcd", "assets_strippedUI/share/registry/res/registry_en-US.xcd"]
236     doFirst {
237         file('assets_strippedUI/share/registry/res').mkdirs()
238     }
241 task createRCfiles {
242     inputs.file "liboSettings.gradle"
243     dependsOn copyUnpackAssets, copyAssets
244     def sofficerc     = file('assets/unpack/program/sofficerc')
245     def fundamentalrc = file('assets/program/fundamentalrc')
246     def bootstraprc   = file('assets/program/bootstraprc')
247     def unorc         = file('assets/program/unorc')
248     def versionrc     = file('assets/program/versionrc')
250     outputs.files sofficerc, fundamentalrc, unorc, bootstraprc, versionrc
252     doLast {
253         sofficerc.text = '''\
254             [Bootstrap]
255             Logo=1
256             NativeProgress=1
257             URE_BOOTSTRAP=file:///assets/program/fundamentalrc
258             HOME=$APP_DATA_DIR/cache
259             OSL_SOCKET_PATH=$APP_DATA_DIR/cache
260             '''.stripIndent()
262         fundamentalrc.text =  '''\
263             [Bootstrap]
264             LO_LIB_DIR=file://$APP_DATA_DIR/lib/
265             BRAND_BASE_DIR=file:///assets
266             CONFIGURATION_LAYERS=xcsxcu:${BRAND_BASE_DIR}/share/registry res:${BRAND_BASE_DIR}/share/registry
267             URE_BIN_DIR=file:///assets/ure/bin/dir/nothing-here/we-can/exec-anyway
268             '''.stripIndent()
270         bootstraprc.text =  '''\
271             [Bootstrap]
272             InstallMode=<installmode>
273             ProductKey=LibreOffice '''+ "${liboVersionMajor}.${liboVersionMinor}" + '''
274             UserInstallation=file://$APP_DATA_DIR
275             '''.stripIndent()
277         unorc.text = '''\
278             [Bootstrap]
279             URE_INTERNAL_LIB_DIR=file://$APP_DATA_DIR/lib/
280             UNO_TYPES=file://$APP_DATA_DIR/program/udkapi.rdb file://$APP_DATA_DIR/program/offapi.rdb file://$APP_DATA_DIR/program/oovbaapi.rdb
281             UNO_SERVICES=file:///assets/program/services.rdb file:///assets/program/services/services.rdb
282             '''.stripIndent()
284         versionrc.text = '''\
285             [Version]
286             AllLanguages=en-US
287             buildid=''' + "${liboGitFullCommit}" + '''
288             ReferenceOOoMajorMinor=4.1
289             '''.stripIndent()
290     }
293 // creating the UI stuff is cheap, don't bother only applying it for the flavor...
294 preBuild.dependsOn 'createRCfiles',
295         'createStrippedConfigMain',
296         'createStrippedConfigRegistry',
297         'createFullConfig'
299 clean.dependsOn 'cleanCopyAssets',
300         'cleanCreateStrippedConfig',
301         'cleanCreateFullConfig'