Branch libreoffice-6-3
[LibreOffice.git] / android / source / build.gradle
blobe1358684b05a6da0b6350865b7ee3c721706ea75
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.1.3'
23     }
26 // compile-time dependencies
27 dependencies {
28     implementation fileTree(dir: "${liboInstdir}/${liboUREJavaFolder}", include: [
29             "java_uno.jar",
30             "juh.jar",
31             "jurt.jar",
32             "ridl.jar",
33             "unoloader.jar"
34     ])
35     implementation files("${liboInstdir}/${liboShareJavaFolder}/unoil.jar")
36     debugImplementation(name:'owncloud_android_lib-debug', ext:'aar')
37     releaseImplementation(name:'owncloud_android_lib-release', ext:'aar')
38     implementation 'com.android.support:design:27.1.1' // also pulls-in corresponding support libraries
39     implementation 'com.android.support.constraint:constraint-layout:1.1.2'
42 android {
43     compileSdkVersion 26
44     buildToolsVersion "27.0.3"
45     compileOptions {
46         // silence some java-language features hints
47         sourceCompatibility 6
48     }
49     // uses non-conventional source layout, so need to reconfigure accordingly
50     // ToDo move to conventional layout, so stuff can be stripped down.
51     sourceSets {
52         main.manifest.srcFile 'AndroidManifest.xml'
53         main.assets.srcDirs = ['assets']
54         main.res.srcDirs = ['res']
55         main.java.srcDirs = ['../Bootstrap/src', 'src/java']
56         main.jniLibs.srcDirs = ['jniLibs']
57         main.jni.srcDirs = [] // don't attempt to build native-lib via gradle
58         // the configuration data that might be stripped or not
59         fullUI.assets.srcDirs 'assets_fullUI'
60         strippedUI.assets.srcDirs 'assets_strippedUI'
61         strippedUIEditing.assets.srcDirs 'assets_strippedUI'
62     }
63     defaultConfig {
64         minSdkVersion 14
65         targetSdkVersion 26
66         vectorDrawables.useSupportLibrary = true
67     }
68     buildTypes {
69         debug {
70             // make android studio happy...
71             jniDebuggable true
72             // would work just fine with external, but setting emulator up is a little more work
73             manifestPlaceholders = [installLocation: "auto", extractNativeLibs: "false"]
74         }
75         release {
76             // need to extract native libs (allow to compress them in apk), since otherwise would
77             // exceed maximum size for playstore
78             manifestPlaceholders = [installLocation: "preferExternal", extractNativeLibs: "true"]
79         }
80     }
82     flavorDimensions "default"
83     productFlavors {
84         strippedUI {
85             dimension "default"
86             buildConfigField 'boolean', 'ALLOW_EDITING', 'false'
87         }
88         strippedUIEditing {
89             dimension "default"
90             buildConfigField 'boolean', 'ALLOW_EDITING', 'true'
91             versionNameSuffix "-editing"
92         }
93         fullUI.dimension "default"
94     }
97 /* remark inherited from makefile:
98 Then "assets". Let the directory structure under assets mimic
99 that under solver for now.
101 Please note that I have no idea what all of this is really necessary and for
102 much of this stuff being copied, no idea whether it makes any sense at all.
103 Much of this is copy-pasted from android/qa/sc/Makefile (where a couple of
104 unit tests for sc are built, and those do seem to mostly work) and
105 android/qa/desktop/Makefile (mmeeks's desktop demo, also works to some
106 extent)
107  */
109 // Assets that are unpacked at run-time into the app's data directory. These
110 // are files read by non-LO code, fontconfig and freetype for now, that doesn't
111 // understand "/assets" paths.
112 task copyUnpackAssets(type: Copy) {
113     description "copies assets that need to be extracted on the device"
114     into 'assets/unpack'
115     into('program') {
116         from("${liboInstdir}/${liboEtcFolder}/types") {
117             includes = [
118                     "offapi.rdb",
119                     "oovbaapi.rdb"
120             ]
121         }
122         from("${liboInstdir}/${liboUreMiscFolder}") {
123             includes = ["types.rdb"]
124             rename 'types.rdb', 'udkapi.rdb'
125         }
126     }
127     into('user/fonts') {
128         from "${liboInstdir}/share/fonts/truetype"
129         // Note: restrict list of fonts due to size considerations - no technical reason anymore
130         // ToDo: fonts would be good candidate for using Expansion Files instead
131         includes = [
132                 "Liberation*.ttf",
133                 "Caladea-*.ttf",
134                 "Carlito-*.ttf",
135                 "Gen*.ttf",
136                 "opens___.ttf"
137         ]
138     }
139     into('etc/fonts') {
140         from "./"
141         includes = ['fonts.conf']
142         filter {
143             String line ->
144                 line.replaceAll(
145                         '@@APPLICATION_ID@@', new String("${android.defaultConfig.applicationId}")
146                 )
147         }
148     }
151 task copyAssets(type: Copy) {
152     description "copies assets that can be accessed within the installed apk"
153     into 'assets'
154     from("${liboSrcRoot}/readlicense_oo/license/") {
155         includes = ["LICENSE", "NOTICE"]
156         rename "LICENSE", "license.txt"
157         rename "NOTICE", "notice.txt"
158     }
159     from("${liboExampleDocument}") {
160         rename ".*", "example.odt"
161     }
162     into('program') {
163         from "${liboInstdir}/program"
164         includes = ['services.rdb', 'services/services.rdb']
166         into('resource') {
167             from "${liboInstdir}/${liboSharedResFolder}"
168             includes = ['*en-US.res']
169         }
170     }
171     into('share') {
172         from "${liboInstdir}/share"
173         // Filter data is needed by e.g. the drawingML preset shape import.
174         includes = ['registry/**', 'filter/**']
175         // those two get processed by mobile-config.py
176         excludes = ['registry/main.xcd', 'registry/res/registry_en-US.xcd']
177     }
180 task createFullConfig(type: Copy) {
181     // grab dir to clear whole hierarchy on clean target
182     outputs.dir "assets_fullUI"
183     into 'assets_fullUI/share/config/soffice.cfg'
184     from "${liboInstdir}/share/config/soffice.cfg"
187 task createStrippedConfig {
188     def preserveDir = file("assets_strippedUI/share/config/soffice.cfg/empty")
189     outputs.dir "assets_strippedUI"
190     outputs.dir "assets_strippedUI/share/registry/res"
191     outputs.file preserveDir
193     doLast {
194         file('assets_strippedUI/share/registry/res').mkdirs()
195         file("assets_strippedUI/share/config/soffice.cfg").mkdirs()
196         // just empty file
197         preserveDir.text = ""
198     }
202 task createStrippedConfigMain(type: Exec) {
203     dependsOn 'createStrippedConfig'
204     inputs.files "${liboInstdir}/share/registry/main.xcd", "${liboSrcRoot}/android/mobile-config.py"
205     outputs.file "assets_strippedUI/share/registry/main.xcd"
206     executable "${liboSrcRoot}/android/mobile-config.py"
207     args = ["${liboInstdir}/share/registry/main.xcd", "assets_strippedUI/share/registry/main.xcd"]
210 task createStrippedConfigRegistry(type: Exec) {
211     dependsOn 'createStrippedConfig'
212     inputs.files "${liboInstdir}/share/registry/res/registry_en-US.xcd", "${liboSrcRoot}/android/mobile-config.py"
213     outputs.file "assets_strippedUI/share/registry/res/registry_en-US.xcd"
214     executable "${liboSrcRoot}/android/mobile-config.py"
215     args = ["${liboInstdir}/share/registry/res/registry_en-US.xcd", "assets_strippedUI/share/registry/res/registry_en-US.xcd"]
216     doFirst {
217         file('assets_strippedUI/share/registry/res').mkdirs()
218     }
221 task createRCfiles {
222     inputs.file "liboSettings.gradle"
223     dependsOn copyUnpackAssets, copyAssets
224     def sofficerc     = file('assets/unpack/program/sofficerc')
225     def fundamentalrc = file('assets/program/fundamentalrc')
226     def bootstraprc   = file('assets/program/bootstraprc')
227     def unorc         = file('assets/program/unorc')
228     def versionrc     = file('assets/program/versionrc')
230     outputs.files sofficerc, fundamentalrc, unorc, bootstraprc, versionrc
232     doLast {
233         sofficerc.text = '''\
234             [Bootstrap]
235             Logo=1
236             NativeProgress=1
237             URE_BOOTSTRAP=file:///assets/program/fundamentalrc
238             HOME=$APP_DATA_DIR/cache
239             OSL_SOCKET_PATH=$APP_DATA_DIR/cache
240             '''.stripIndent()
242         fundamentalrc.text =  '''\
243             [Bootstrap]
244             LO_LIB_DIR=file://$APP_DATA_DIR/lib/
245             BRAND_BASE_DIR=file:///assets
246             CONFIGURATION_LAYERS=xcsxcu:${BRAND_BASE_DIR}/share/registry res:${BRAND_BASE_DIR}/share/registry
247             URE_BIN_DIR=file:///assets/ure/bin/dir/nothing-here/we-can/exec-anyway
248             '''.stripIndent()
250         bootstraprc.text =  '''\
251             [Bootstrap]
252             InstallMode=<installmode>
253             ProductKey=LibreOffice '''+ "${liboVersionMajor}.${liboVersionMinor}" + '''
254             UserInstallation=file://$APP_DATA_DIR
255             '''.stripIndent()
257         unorc.text = '''\
258             [Bootstrap]
259             URE_INTERNAL_LIB_DIR=file://$APP_DATA_DIR/lib/
260             UNO_TYPES=file://$APP_DATA_DIR/program/udkapi.rdb file://$APP_DATA_DIR/program/offapi.rdb file://$APP_DATA_DIR/program/oovbaapi.rdb
261             UNO_SERVICES=file:///assets/program/services.rdb file:///assets/program/services/services.rdb
262             '''.stripIndent()
264         versionrc.text = '''\
265             [Version]
266             AllLanguages=en-US
267             BuildVersion=
268             buildid=''' + "${liboGitFullCommit}" + '''
269             ReferenceOOoMajorMinor=4.1
270             '''.stripIndent()
271     }
274 // creating the UI stuff is cheap, don't bother only applying it for the flavor..
275 preBuild.dependsOn 'createRCfiles',
276         'createStrippedConfigMain',
277         'createStrippedConfigRegistry',
278         'createFullConfig'
280 clean.dependsOn 'cleanCopyAssets',
281         'cleanCreateStrippedConfig',
282         'cleanCreateFullConfig'