Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / android / source / build.gradle
blobe931124577b11188a3e84d97e5f05704e6ae1036
1 apply plugin: 'com.android.application'
2 // buildhost settings - paths and the like
3 apply from: 'liboSettings.gradle'
5 allprojects {
6     repositories {
7         mavenCentral()
8         maven {
9             url "https://ipv6.repo1.maven.org/maven2"
10         }
11         google()
12     }
14 //build-time dependencies - android plugin for gradle
15 buildscript {
16     repositories {
17         mavenCentral()
18         maven {
19             url "https://ipv6.repo1.maven.org/maven2"
20         }
21         google()
22     }
23     dependencies {
24         classpath 'com.android.tools.build:gradle:7.4.2'
25     }
28 // compile-time dependencies
29 dependencies {
30     implementation fileTree(dir: "${liboInstdir}/${liboUREJavaFolder}", include: [
31             "java_uno.jar",
32             "libreoffice.jar",
33             "unoloader.jar"
34     ])
35     implementation 'com.google.android.material:material:1.8.0'
36     implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
37     implementation "androidx.multidex:multidex:2.0.1"
40 android {
41     namespace 'org.libreoffice'
42     compileSdkVersion 33
43     // uses non-conventional source layout, so need to reconfigure accordingly
44     // ToDo move to conventional layout, so stuff can be stripped down.
45     sourceSets {
46         main.manifest.srcFile 'AndroidManifest.xml'
47         main.assets.srcDirs = ['assets']
48         main.res.srcDirs = ['res', 'res_generated']
49         main.java.srcDirs = ['../Bootstrap/src', 'src/java']
50         main.jniLibs.srcDirs = ["${liboJniLibsdir}"]
51         // the configuration data that might be stripped or not
52         fullUI.assets.srcDirs 'assets_fullUI'
53         strippedUI.assets.srcDirs 'assets_strippedUI'
54         strippedUIEditing.assets.srcDirs 'assets_strippedUI'
55     }
56     defaultConfig {
57         // minSdkVersion is set in liboSettings.gradle
58         targetSdkVersion 33
59         // multidex needed when > 65,536 methods referenced with minSdKVersion < 21
60         // s. https://developer.android.com/studio/build/multidex
61         multiDexEnabled true
62         vectorDrawables.useSupportLibrary = true
63     }
64     buildTypes {
65         debug {
66             // make android studio happy...
67             jniDebuggable true
68             // would work just fine with external, but setting emulator up is a little more work
69             manifestPlaceholders = [installLocation: "auto"]
70         }
71         release {
72             manifestPlaceholders = [installLocation: "preferExternal"]
73         }
74     }
76     flavorDimensions "default"
77     productFlavors {
78         strippedUI {
79             dimension "default"
80             buildConfigField 'boolean', 'ALLOW_EDITING', 'false'
81         }
82         strippedUIEditing {
83             dimension "default"
84             buildConfigField 'boolean', 'ALLOW_EDITING', 'true'
85         }
86         fullUI.dimension "default"
87     }
88     lint {
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'
152     // include icons, Impress styles and required .ui files
153     into ('share') {
154         into ('config') {
155             from ("${liboInstdir}/share/config")
156             includes = ['images_**.zip',
157                         '**/simpress/**.xml',
158                         '**/annotation.ui',
159                         '**/hfmenubutton.ui',
160                         '**/inforeadonlydialog.ui',
161                         '**/pbmenubutton.ui',
162                         '**/scrollbars.ui',
163                         '**/tabbuttons.ui',
164                         '**/tabviewbar.ui'
165                         ]
166         }
167     }
169     into('program') {
170         from "${liboInstdir}/program"
171         includes = ['services.rdb', 'services/services.rdb']
173         into('resource') {
174             from "${liboInstdir}/${liboSharedResFolder}"
175             includes = ['*en-US.res']
176         }
177     }
178     into('share') {
179         from("${liboInstdir}/share") {
180             // Filter data is needed by e.g. the drawingML preset shape import.
181             includes = ['registry/**', 'filter/**']
182             // those two get processed by mobile-config.py
183             excludes = ['registry/main.xcd', 'registry/res/registry_en-US.xcd']
184         }
185         // separate data files for Chinese and Japanese
186         from("${liboWorkdir}/CustomTarget/i18npool/breakiterator/") {
187             include '*.data'
188         }
189     }
192 task copyAppResources(type: Copy) {
193     description "copies documents to make them available as app resources"
194     into 'res_generated/raw'
195     from("${liboInstdir}") {
196         includes = ["LICENSE", "NOTICE"]
197         rename "LICENSE", "license.txt"
198         rename "NOTICE", "notice.txt"
199     }
200     from("${liboExampleDocument}") {
201         rename ".*", "example.odt"
202     }
205 task createFullConfig(type: Copy) {
206     // grab dir to clear whole hierarchy on clean target
207     outputs.dir "assets_fullUI"
208     into 'assets_fullUI/share/config/soffice.cfg'
209     from "${liboInstdir}/share/config/soffice.cfg"
212 task createStrippedConfig {
213     def preserveDir = file("assets_strippedUI/share/config/soffice.cfg/empty")
214     outputs.dir "assets_strippedUI"
215     outputs.dir "assets_strippedUI/share/registry/res"
216     outputs.file preserveDir
218     doLast {
219         file('assets_strippedUI/share/registry/res').mkdirs()
220         file("assets_strippedUI/share/config/soffice.cfg").mkdirs()
221         // just empty file
222         preserveDir.text = ""
223     }
227 task createStrippedConfigMain(type: Exec) {
228     dependsOn 'createStrippedConfig'
229     inputs.files "${liboInstdir}/share/registry/main.xcd", "${liboSrcRoot}/android/mobile-config.py"
230     outputs.file "assets_strippedUI/share/registry/main.xcd"
231     executable "${liboSrcRoot}/android/mobile-config.py"
232     args = ["${liboInstdir}/share/registry/main.xcd", "assets_strippedUI/share/registry/main.xcd"]
235 task createStrippedConfigRegistry(type: Exec) {
236     dependsOn 'createStrippedConfig'
237     inputs.files "${liboInstdir}/share/registry/res/registry_en-US.xcd", "${liboSrcRoot}/android/mobile-config.py"
238     outputs.file "assets_strippedUI/share/registry/res/registry_en-US.xcd"
239     executable "${liboSrcRoot}/android/mobile-config.py"
240     args = ["${liboInstdir}/share/registry/res/registry_en-US.xcd", "assets_strippedUI/share/registry/res/registry_en-US.xcd"]
241     doFirst {
242         file('assets_strippedUI/share/registry/res').mkdirs()
243     }
246 task createRCfiles {
247     inputs.file "liboSettings.gradle"
248     dependsOn copyUnpackAssets, copyAssets
249     def sofficerc     = file('assets/unpack/program/sofficerc')
250     def fundamentalrc = file('assets/program/fundamentalrc')
251     def bootstraprc   = file('assets/program/bootstraprc')
252     def unorc         = file('assets/program/unorc')
253     def versionrc     = file('assets/program/versionrc')
255     outputs.files sofficerc, fundamentalrc, unorc, bootstraprc, versionrc
257     doLast {
258         sofficerc.text = '''\
259             [Bootstrap]
260             Logo=1
261             NativeProgress=1
262             URE_BOOTSTRAP=file:///assets/program/fundamentalrc
263             HOME=$APP_DATA_DIR/cache
264             OSL_SOCKET_PATH=$APP_DATA_DIR/cache
265             '''.stripIndent()
267         fundamentalrc.text =  '''\
268             [Bootstrap]
269             LO_LIB_DIR=file://$APP_DATA_DIR/lib/
270             BRAND_BASE_DIR=file:///assets
271             BRAND_SHARE_SUBDIR=share
272             CONFIGURATION_LAYERS=xcsxcu:${BRAND_BASE_DIR}/share/registry res:${BRAND_BASE_DIR}/share/registry
273             URE_BIN_DIR=file:///assets/ure/bin/dir/nothing-here/we-can/exec-anyway
274             '''.stripIndent()
276         bootstraprc.text =  '''\
277             [Bootstrap]
278             InstallMode=<installmode>
279             ProductKey=LibreOffice '''+ "${liboVersionMajor}.${liboVersionMinor}" + '''
280             UserInstallation=file://$APP_DATA_DIR
281             '''.stripIndent()
283         unorc.text = '''\
284             [Bootstrap]
285             URE_INTERNAL_LIB_DIR=file://$APP_DATA_DIR/lib/
286             UNO_TYPES=file://$APP_DATA_DIR/program/udkapi.rdb file://$APP_DATA_DIR/program/offapi.rdb file://$APP_DATA_DIR/program/oovbaapi.rdb
287             UNO_SERVICES=file:///assets/program/services.rdb file:///assets/program/services/services.rdb
288             '''.stripIndent()
290         versionrc.text = '''\
291             [Version]
292             AllLanguages=en-US
293             buildid=''' + "${liboGitFullCommit}" + '''
294             ReferenceOOoMajorMinor=4.1
295             '''.stripIndent()
296     }
299 // creating the UI stuff is cheap, don't bother only applying it for the flavor...
300 preBuild.dependsOn 'createRCfiles',
301         'createStrippedConfigMain',
302         'createStrippedConfigRegistry',
303         'createFullConfig',
304         'copyAppResources'
306 clean.dependsOn 'cleanCopyAssets',
307         'cleanCreateStrippedConfig',
308         'cleanCreateFullConfig'