Avoid potential negative array index access to cached text.
[LibreOffice.git] / android / source / build.gradle
blob8843330b7ba549814aedb40c5cf5ef38f6b0eee0
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:8.2.0'
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.10.0'
36     implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
37     implementation "androidx.multidex:multidex:2.0.1"
40 android {
41     namespace 'org.libreoffice'
42     compileSdk 34
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 34
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 // show warnings about use of deprecated API
95 tasks.withType(JavaCompile).configureEach {
96     options.deprecation = true
99 /* remark inherited from makefile:
100 Then "assets". Let the directory structure under assets mimic
101 that under solver for now.
103 Please note that I have no idea what all of this is really necessary and for
104 much of this stuff being copied, no idea whether it makes any sense at all.
105 Much of this is copy-pasted from android/qa/sc/Makefile (where a couple of
106 unit tests for sc are built, and those do seem to mostly work) and
107 android/qa/desktop/Makefile (mmeeks's desktop demo, also works to some
108 extent)
109  */
111 // Assets that are unpacked at run-time into the app's data directory. These
112 // are files read by non-LO code, fontconfig and freetype for now, that doesn't
113 // understand "/assets" paths.
114 task copyUnpackAssets(type: Copy) {
115     description "copies assets that need to be extracted on the device"
116     into 'assets/unpack'
117     into('program') {
118         from("${liboInstdir}/${liboEtcFolder}/types") {
119             includes = [
120                     "offapi.rdb",
121                     "oovbaapi.rdb"
122             ]
123         }
124         from("${liboInstdir}/${liboUreMiscFolder}") {
125             includes = ["types.rdb"]
126             rename 'types.rdb', 'udkapi.rdb'
127         }
128     }
129     into('user/fonts') {
130         from "${liboInstdir}/share/fonts/truetype"
131         // Note: restrict list of fonts due to size considerations - no technical reason anymore
132         // ToDo: fonts would be good candidate for using Expansion Files instead
133         includes = [
134                 "Liberation*.ttf",
135                 "Caladea-*.ttf",
136                 "Carlito-*.ttf",
137                 "Gen*.ttf",
138                 "opens___.ttf"
139         ]
140     }
141     into('etc/fonts') {
142         from "./"
143         includes = ['fonts.conf']
144         filter {
145             String line ->
146                 line.replaceAll(
147                         '@@APPLICATION_ID@@', new String("${android.defaultConfig.applicationId}")
148                 )
149         }
150     }
153 task copyAssets(type: Copy) {
154     description "copies assets that can be accessed within the installed apk"
155     into 'assets'
157     // include icons, Impress styles and required .ui files
158     into ('share') {
159         into ('config') {
160             from ("${liboInstdir}/share/config")
161             includes = ['images_**.zip',
162                         '**/simpress/**.xml',
163                         '**/annotation.ui',
164                         '**/hfmenubutton.ui',
165                         '**/inforeadonlydialog.ui',
166                         '**/pbmenubutton.ui',
167                         '**/scrollbars.ui',
168                         '**/tabbuttons.ui',
169                         '**/tabviewbar.ui'
170                         ]
171         }
172     }
174     into('program') {
175         from "${liboInstdir}/program"
176         includes = ['services.rdb', 'services/services.rdb']
178         into('resource') {
179             from "${liboInstdir}/${liboSharedResFolder}"
180             includes = ['*en-US.res']
181         }
182     }
183     into('share') {
184         from("${liboInstdir}/share") {
185             // Filter data is needed by e.g. the drawingML preset shape import.
186             includes = ['registry/**', 'filter/**']
187             // those two get processed by mobile-config.py
188             excludes = ['registry/main.xcd', 'registry/res/registry_en-US.xcd']
189         }
190         // separate data files for Chinese and Japanese
191         from("${liboWorkdir}/CustomTarget/i18npool/breakiterator/") {
192             include '*.data'
193         }
194     }
197 task copyAppResources(type: Copy) {
198     description "copies documents to make them available as app resources"
199     into 'res_generated/raw'
200     from("${liboInstdir}") {
201         includes = ["LICENSE", "NOTICE"]
202         rename "LICENSE", "license.txt"
203         rename "NOTICE", "notice.txt"
204     }
207 task createFullConfig(type: Copy) {
208     // grab dir to clear whole hierarchy on clean target
209     outputs.dir "assets_fullUI"
210     into 'assets_fullUI/share/config/soffice.cfg'
211     from "${liboInstdir}/share/config/soffice.cfg"
214 task createStrippedConfig {
215     def preserveDir = file("assets_strippedUI/share/config/soffice.cfg/empty")
216     outputs.dir "assets_strippedUI"
217     outputs.dir "assets_strippedUI/share/registry/res"
218     outputs.file preserveDir
220     doLast {
221         file('assets_strippedUI/share/registry/res').mkdirs()
222         file("assets_strippedUI/share/config/soffice.cfg").mkdirs()
223         // just empty file
224         preserveDir.text = ""
225     }
229 task createStrippedConfigMain(type: Exec) {
230     dependsOn 'createStrippedConfig'
231     inputs.files "${liboInstdir}/share/registry/main.xcd", "${liboSrcRoot}/android/mobile-config.py"
232     outputs.file "assets_strippedUI/share/registry/main.xcd"
233     executable "${liboSrcRoot}/android/mobile-config.py"
234     args = ["${liboInstdir}/share/registry/main.xcd", "assets_strippedUI/share/registry/main.xcd"]
237 task createStrippedConfigRegistry(type: Exec) {
238     dependsOn 'createStrippedConfig'
239     inputs.files "${liboInstdir}/share/registry/res/registry_en-US.xcd", "${liboSrcRoot}/android/mobile-config.py"
240     outputs.file "assets_strippedUI/share/registry/res/registry_en-US.xcd"
241     executable "${liboSrcRoot}/android/mobile-config.py"
242     args = ["${liboInstdir}/share/registry/res/registry_en-US.xcd", "assets_strippedUI/share/registry/res/registry_en-US.xcd"]
243     doFirst {
244         file('assets_strippedUI/share/registry/res').mkdirs()
245     }
248 task createRCfiles {
249     inputs.file "liboSettings.gradle"
250     dependsOn copyUnpackAssets, copyAssets
251     def sofficerc     = file('assets/unpack/program/sofficerc')
252     def fundamentalrc = file('assets/program/fundamentalrc')
253     def bootstraprc   = file('assets/program/bootstraprc')
254     def unorc         = file('assets/program/unorc')
255     def versionrc     = file('assets/program/versionrc')
257     outputs.files sofficerc, fundamentalrc, unorc, bootstraprc, versionrc
259     doLast {
260         sofficerc.text = '''\
261             [Bootstrap]
262             Logo=1
263             NativeProgress=1
264             URE_BOOTSTRAP=file:///assets/program/fundamentalrc
265             HOME=$APP_DATA_DIR/cache
266             OSL_SOCKET_PATH=$APP_DATA_DIR/cache
267             '''.stripIndent()
269         fundamentalrc.text =  '''\
270             [Bootstrap]
271             LO_LIB_DIR=file://$APP_DATA_DIR/lib/
272             BRAND_BASE_DIR=file:///assets
273             BRAND_SHARE_SUBDIR=share
274             CONFIGURATION_LAYERS=xcsxcu:${BRAND_BASE_DIR}/share/registry res:${BRAND_BASE_DIR}/share/registry
275             URE_BIN_DIR=file:///assets/ure/bin/dir/nothing-here/we-can/exec-anyway
276             '''.stripIndent()
278         bootstraprc.text =  '''\
279             [Bootstrap]
280             InstallMode=<installmode>
281             ProductKey=LibreOffice '''+ "${liboVersionMajor}.${liboVersionMinor}" + '''
282             UserInstallation=file://$APP_DATA_DIR
283             '''.stripIndent()
285         unorc.text = '''\
286             [Bootstrap]
287             URE_INTERNAL_LIB_DIR=file://$APP_DATA_DIR/lib/
288             UNO_TYPES=file://$APP_DATA_DIR/program/udkapi.rdb file://$APP_DATA_DIR/program/offapi.rdb file://$APP_DATA_DIR/program/oovbaapi.rdb
289             UNO_SERVICES=file:///assets/program/services.rdb file:///assets/program/services/services.rdb
290             '''.stripIndent()
292         versionrc.text = '''\
293             [Version]
294             AllLanguages=en-US
295             buildid=''' + "${liboGitFullCommit}" + '''
296             ReferenceOOoMajorMinor=4.1
297             '''.stripIndent()
298     }
301 // creating the UI stuff is cheap, don't bother only applying it for the flavor...
302 preBuild.dependsOn 'createRCfiles',
303         'createStrippedConfigMain',
304         'createStrippedConfigRegistry',
305         'createFullConfig',
306         'copyAppResources'
308 clean.dependsOn 'cleanCopyAssets',
309         'cleanCreateStrippedConfig',
310         'cleanCreateFullConfig'