tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / android / source / build.gradle
blob84b9f4233bd05a99948c90fcb6cd373c992f5fe4
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.6.1'
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.12.0'
36     implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
37     implementation 'androidx.preference:preference:1.2.1'
40 base {
41     archivesName = "LibreOfficeViewer"
44 android {
45     namespace 'org.libreoffice'
46     compileSdk 34
47     buildFeatures {
48         buildConfig = true
49     }
50     // uses non-conventional source layout, so need to reconfigure accordingly
51     // ToDo move to conventional layout, so stuff can be stripped down.
52     sourceSets {
53         main.manifest.srcFile 'AndroidManifest.xml'
54         main.assets.srcDirs = ['assets']
55         main.res.srcDirs = ['res', 'res_generated']
56         main.java.srcDirs = ['../Bootstrap/src', 'src/java']
57         main.jniLibs.srcDirs = ["${liboJniLibsdir}"]
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 is set in liboSettings.gradle
65         targetSdkVersion 34
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"]
74         }
75         release {
76             manifestPlaceholders = [installLocation: "preferExternal"]
77         }
78     }
80     flavorDimensions "default"
81     productFlavors {
82         strippedUI {
83             dimension "default"
84             buildConfigField 'boolean', 'ALLOW_EDITING', 'false'
85         }
86         strippedUIEditing {
87             dimension "default"
88             buildConfigField 'boolean', 'ALLOW_EDITING', 'true'
89         }
90         fullUI.dimension "default"
91     }
92     lint {
93         warningsAsErrors true
94         // ignore missing or extra translations, since these are tracked/managed via Weblate
95         ignore 'ExtraTranslation', 'MissingTranslation'
96         // don't error-out on external updates (new gradle plugin, library versions
97         // or target API become available)
98         // don't error-out on TypographyEllipsis, since this can be introduced with
99         // new translations, and those are handled in Weblate
100         informational 'AndroidGradlePluginVersion', 'GradleDependency', 'NewerVersionAvailable', 'OldTargetApi', 'TypographyEllipsis'
101         // don't fail on pre-existing issues
102         // These should be dealt with at some point, though.
103         // To update lint-baseline.xml, just remove the file and run the build again.
104         baseline file("lint-baseline.xml")
105         // s.a. lint.xml that contains further config
106     }
109 // show warnings about use of deprecated API
110 tasks.withType(JavaCompile).configureEach {
111     options.deprecation = true
114 /* remark inherited from makefile:
115 Then "assets". Let the directory structure under assets mimic
116 that under solver for now.
118 Please note that I have no idea what all of this is really necessary and for
119 much of this stuff being copied, no idea whether it makes any sense at all.
120 Much of this is copy-pasted from android/qa/sc/Makefile (where a couple of
121 unit tests for sc are built, and those do seem to mostly work) and
122 android/qa/desktop/Makefile (mmeeks's desktop demo, also works to some
123 extent)
124  */
126 // Assets that are unpacked at run-time into the app's data directory. These
127 // are files read by non-LO code, fontconfig and freetype for now, that doesn't
128 // understand "/assets" paths.
129 task copyUnpackAssets(type: Copy) {
130     description "copies assets that need to be extracted on the device"
131     into 'assets/unpack'
132     into('program') {
133         from("${liboInstdir}/${liboEtcFolder}/types") {
134             includes = [
135                     "offapi.rdb",
136                     "oovbaapi.rdb"
137             ]
138         }
139         from("${liboInstdir}/${liboUreMiscFolder}") {
140             includes = ["types.rdb"]
141             rename 'types.rdb', 'udkapi.rdb'
142         }
143     }
144     into('user/fonts') {
145         from "${liboInstdir}/share/fonts/truetype"
146         // Note: restrict list of fonts due to size considerations - no technical reason anymore
147         // ToDo: fonts would be good candidate for using Expansion Files instead
148         includes = [
149                 "Liberation*.ttf",
150                 "Caladea-*.ttf",
151                 "Carlito-*.ttf",
152                 "Gen*.ttf",
153                 "opens___.ttf"
154         ]
155     }
156     into('etc/fonts') {
157         from "./"
158         includes = ['fonts.conf']
159         filter {
160             String line ->
161                 line.replaceAll(
162                         '@@APPLICATION_ID@@', new String("${android.defaultConfig.applicationId}")
163                 )
164         }
165     }
168 task copyAssets(type: Copy) {
169     description "copies assets that can be accessed within the installed apk"
170     into 'assets'
172     // include icons, Impress styles and required .ui files
173     into ('share') {
174         into ('config') {
175             from ("${liboInstdir}/share/config")
176             includes = ['images_**.zip',
177                         '**/simpress/**.xml',
178                         '**/annotation.ui',
179                         '**/hfmenubutton.ui',
180                         '**/inforeadonlydialog.ui',
181                         '**/pbmenubutton.ui',
182                         '**/scrollbars.ui',
183                         '**/tabbuttons.ui',
184                         '**/tabviewbar.ui'
185                         ]
186         }
187     }
189     into('program') {
190         from "${liboInstdir}/program"
191         includes = ['services.rdb', 'services/services.rdb']
193         into('resource') {
194             from "${liboInstdir}/${liboSharedResFolder}"
195             includes = ['*en-US.res']
196         }
197     }
198     into('share') {
199         from("${liboInstdir}/share") {
200             // Filter data is needed by e.g. the drawingML preset shape import.
201             includes = ['registry/**', 'filter/**']
202             // those two get processed by mobile-config.py
203             excludes = ['registry/main.xcd', 'registry/res/registry_en-US.xcd']
204         }
205         // separate data files for Chinese and Japanese
206         from("${liboWorkdir}/CustomTarget/i18npool/breakiterator/") {
207             include '*.data'
208         }
209     }
212 task copyAppResources(type: Copy) {
213     description "copies documents to make them available as app resources"
214     into 'res_generated/raw'
215     from("${liboInstdir}") {
216         includes = ["LICENSE", "NOTICE"]
217         rename "LICENSE", "license.txt"
218         rename "NOTICE", "notice.txt"
219     }
222 task createFullConfig(type: Copy) {
223     // grab dir to clear whole hierarchy on clean target
224     outputs.dir "assets_fullUI"
225     into 'assets_fullUI/share/config/soffice.cfg'
226     from "${liboInstdir}/share/config/soffice.cfg"
229 task createStrippedConfig {
230     def preserveDir = file("assets_strippedUI/share/config/soffice.cfg/empty")
231     outputs.dir "assets_strippedUI"
232     outputs.dir "assets_strippedUI/share/registry/res"
233     outputs.file preserveDir
235     doLast {
236         file('assets_strippedUI/share/registry/res').mkdirs()
237         file("assets_strippedUI/share/config/soffice.cfg").mkdirs()
238         // just empty file
239         preserveDir.text = ""
240     }
244 task createStrippedConfigMain(type: Exec) {
245     dependsOn 'createStrippedConfig'
246     inputs.files "${liboInstdir}/share/registry/main.xcd", "${liboSrcRoot}/android/mobile-config.py"
247     outputs.file "assets_strippedUI/share/registry/main.xcd"
248     executable "${liboSrcRoot}/android/mobile-config.py"
249     args = ["${liboInstdir}/share/registry/main.xcd", "assets_strippedUI/share/registry/main.xcd"]
252 task createStrippedConfigRegistry(type: Exec) {
253     dependsOn 'createStrippedConfig'
254     inputs.files "${liboInstdir}/share/registry/res/registry_en-US.xcd", "${liboSrcRoot}/android/mobile-config.py"
255     outputs.file "assets_strippedUI/share/registry/res/registry_en-US.xcd"
256     executable "${liboSrcRoot}/android/mobile-config.py"
257     args = ["${liboInstdir}/share/registry/res/registry_en-US.xcd", "assets_strippedUI/share/registry/res/registry_en-US.xcd"]
258     doFirst {
259         file('assets_strippedUI/share/registry/res').mkdirs()
260     }
263 task createRCfiles {
264     inputs.file "liboSettings.gradle"
265     dependsOn copyUnpackAssets, copyAssets
266     def sofficerc     = file('assets/unpack/program/sofficerc')
267     def fundamentalrc = file('assets/program/fundamentalrc')
268     def bootstraprc   = file('assets/program/bootstraprc')
269     def unorc         = file('assets/program/unorc')
270     def versionrc     = file('assets/program/versionrc')
272     outputs.files sofficerc, fundamentalrc, unorc, bootstraprc, versionrc
274     doLast {
275         sofficerc.text = '''\
276             [Bootstrap]
277             Logo=1
278             NativeProgress=1
279             URE_BOOTSTRAP=file:///assets/program/fundamentalrc
280             HOME=$APP_DATA_DIR/cache
281             OSL_SOCKET_PATH=$APP_DATA_DIR/cache
282             '''.stripIndent()
284         fundamentalrc.text =  '''\
285             [Bootstrap]
286             LO_LIB_DIR=file://$APP_DATA_DIR/lib/
287             BRAND_BASE_DIR=file:///assets
288             BRAND_SHARE_SUBDIR=share
289             CONFIGURATION_LAYERS=xcsxcu:${BRAND_BASE_DIR}/share/registry res:${BRAND_BASE_DIR}/share/registry
290             URE_BIN_DIR=file:///assets/ure/bin/dir/nothing-here/we-can/exec-anyway
291             '''.stripIndent()
293         bootstraprc.text =  '''\
294             [Bootstrap]
295             InstallMode=<installmode>
296             ProductKey=LibreOffice '''+ "${liboVersionMajor}.${liboVersionMinor}" + '''
297             UserInstallation=file://$APP_DATA_DIR
298             '''.stripIndent()
300         unorc.text = '''\
301             [Bootstrap]
302             URE_INTERNAL_LIB_DIR=file://$APP_DATA_DIR/lib/
303             UNO_TYPES=file://$APP_DATA_DIR/program/udkapi.rdb file://$APP_DATA_DIR/program/offapi.rdb file://$APP_DATA_DIR/program/oovbaapi.rdb
304             UNO_SERVICES=file:///assets/program/services.rdb file:///assets/program/services/services.rdb
305             '''.stripIndent()
307         versionrc.text = '''\
308             [Version]
309             AllLanguages=en-US
310             buildid=''' + "${liboGitFullCommit}" + '''
311             ReferenceOOoMajorMinor=4.1
312             '''.stripIndent()
313     }
316 // creating the UI stuff is cheap, don't bother only applying it for the flavor...
317 preBuild.dependsOn 'createRCfiles',
318         'createStrippedConfigMain',
319         'createStrippedConfigRegistry',
320         'createFullConfig',
321         'copyAppResources'
323 clean.dependsOn 'cleanCopyAssets',
324         'cleanCreateStrippedConfig',
325         'cleanCreateFullConfig'