summaryrefslogtreecommitdiff
path: root/android/lib/build.gradle
blob: 46771f3206912df88d52f88cea71825ba028f0c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
apply plugin: 'com.android.library'

// buildhost settings - paths and the like
apply from: 'libSettings.gradle'

android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        externalNativeBuild {
            cmake {
                arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_STL=c++_shared"
            }
        }
    }

    lintOptions {
        disable 'MissingTranslation'
    }

    buildTypes {
        debug {
            buildConfigField "String", "GIT_COMMIT", "\"${liboGitFullCommit}\""
            ndk {
                abiFilters = []
                abiFilters.addAll("${liboAndroidAbi}".split(' ').collect{it as String})
            }
            debuggable true
        }
        release {
            buildConfigField "String", "GIT_COMMIT", "\"${liboGitFullCommit}\""
            ndk {
                abiFilters = []
                abiFilters.addAll("${liboAndroidAbi}".split(' ').collect{it as String})
            }
            minifyEnabled false // FIXME disabled before we get a good proguardRules for callFakeWebsocketOnMessage calling from C++
            shrinkResources false // FIXME cannot be enabled when minifyEnabled is turned off
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets {
        main {
            // let gradle pack the shared library into apk
            jniLibs.srcDirs = ['src/main/cpp/lib']
        }
    }

    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.material:material:1.1.0-alpha04'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'

}

task copyUnpackAssets(type: Copy) {
    description "copies assets that need to be extracted on the device"
    into 'src/main/assets/unpack'
    into('program') {
        from("${liboInstdir}/${liboEtcFolder}/types") {
            includes = [
                    "offapi.rdb",
                    "oovbaapi.rdb"
            ]
        }
        from("${liboInstdir}/${liboUreMiscFolder}") {
            includes = ["types.rdb"]
            rename 'types.rdb', 'udkapi.rdb'
        }

        into('resource') {
            from "${liboInstdir}/${liboSharedResFolder}"
            includes = ['**']
        }
    }
    into('etc/loolwsd') {
        from('/android/loolkitconfig.xcu')
            includes = [ 'loolkitconfig.xcu' ]
    }
    into('user/fonts') {
        from "${liboInstdir}/share/fonts/truetype"
        // Note: restrict list of fonts due to size considerations - no technical reason anymore
        // ToDo: fonts would be good candidate for using Expansion Files instead
        includes = [
                "EmojiOne*.ttf",
                "Liberation*.ttf",
                "Caladea-*.ttf",
                "Carlito-*.ttf",
                "Gen*.ttf",
                "opens___.ttf"
        ]
    }
    into('etc/fonts') {
        from "${liboSrcRoot}/android/source/"
        includes = ['fonts.conf']
        filter {
            String line ->
                line.replaceAll(
                    '@@APPLICATION_ID@@', new String("${liboApplicationId}")
                ).replaceAll(
                    // FIXME Avoid the Android system fonts for the moment,
                    // the huge Noto Sans fonts have terrible impact on the 1st
                    // start performance.
                    // The real solution would be to either make fontconfig
                    // faster, or at least find a way to avoid only the Noto
                    // Sans, or present a progressbar or something.
                    // For the moment, we just copy the Roboto font (needed
                    // for the dialogs; see LOActivity.copyFonts()) and
                    // remove the system fonts from the config.
                    '<dir>/system/fonts</dir>', new String("")
                )
        }
    }
    into('share') {
        from "${liboInstdir}/share"
        // extensions - for the dictionaries for hunspell
        // liblangtag data is needed for locales like en-CH
        includes = ['extensions/dict-de/**', 'extensions/dict-en/**', 'extensions/dict-es/**', 'extensions/dict-pt-BR/**', 'liblangtag/**']
    }
}

task copyAssets(type: Copy) {
    description "copies assets that can be accessed within the installed apk"
    into 'src/main/assets'
    from("${liboSrcRoot}/instdir/") {
        includes = ["LICENSE.html", "NOTICE"]
        rename "LICENSE.html", "license.html"
        rename "NOTICE", "notice.txt"
    }
    from("${liboExampleDocument}") {
        rename ".*", "example.odt"
    }
    into('program') {
        from "${liboInstdir}/program"
        includes = ['services.rdb', 'services/services.rdb']
    }
    into('share') {
        from "${liboInstdir}/share"
        // Filter data is needed by e.g. the drawingML preset shape import.
        includes = ['registry/**', 'filter/**', 'gallery/**', 'palette/**']
    }
}

task createFullConfig(type: Copy) {
    description "copies various configuration bits into the apk"
    into('src/main/assets/share/config')
    from("${liboInstdir}/share/config") {
        includes = ['soffice.cfg/**', 'images_colibre.zip']
    }
}

task createStrippedConfig {
    def preserveDir = file("src/main/assets/share/config/soffice.cfg/empty")
    outputs.dir "src/main/assets/share/registry/res"
    outputs.file preserveDir

    doLast {
        file('src/main/assets/share/registry/res').mkdirs()
        file("src/main/assets/share/config/soffice.cfg").mkdirs()
        // just empty file
        preserveDir.text = ""
    }
}

task createRCfiles {
    inputs.file "libSettings.gradle"
    dependsOn copyUnpackAssets, copyAssets
    def sofficerc = file('src/main/assets/unpack/program/sofficerc')
    def fundamentalrc = file('src/main/assets/program/fundamentalrc')
    def bootstraprc = file('src/main/assets/program/bootstraprc')
    def unorc = file('src/main/assets/program/unorc')
    def lounorc = file('src/main/assets/program/lounorc')
    def versionrc = file('src/main/assets/program/versionrc')

    outputs.files sofficerc, fundamentalrc, unorc, bootstraprc, versionrc

    doLast {
        sofficerc.text = '''\
[Bootstrap]
Logo=1
NativeProgress=1
URE_BOOTSTRAP=file:///assets/program/fundamentalrc
HOME=$APP_DATA_DIR/cache
OSL_SOCKET_PATH=$APP_DATA_DIR/cache
'''.stripIndent()

        fundamentalrc.text = '''\
[Bootstrap]
LO_LIB_DIR=file://$APP_DATA_DIR/lib/
BRAND_BASE_DIR=file:///assets
BRAND_SHARE_SUBDIR=share
URE_BIN_DIR=file:///assets/ure/bin/dir/nothing-here/we-can/exec-anyway
BAK_EXTENSIONS=${$ORIGIN/lounorc:TMP_EXTENSIONS}
BUNDLED_EXTENSIONS=${$ORIGIN/lounorc:BUNDLED_EXTENSIONS}
BUNDLED_EXTENSIONS_USER=${$ORIGIN/lounorc:BUNDLED_EXTENSIONS_USER}
SHARED_EXTENSIONS_USER=${$ORIGIN/lounorc:SHARED_EXTENSIONS_USER}
UNO_SHARED_PACKAGES_CACHE=${$ORIGIN/lounorc:UNO_SHARED_PACKAGES_CACHE}
TMP_EXTENSIONS=${$ORIGIN/lounorc:TMP_EXTENSIONS}
UNO_USER_PACKAGES_CACHE=${$ORIGIN/lounorc:UNO_USER_PACKAGES_CACHE}
'''.stripIndent()

        bootstraprc.text = '''\
[Bootstrap]
InstallMode=<installmode>
ProductKey=LibreOffice ''' + "${liboVersionMajor}.${liboVersionMinor}" + '''
UserInstallation=file://$APP_DATA_DIR
'''.stripIndent()

        unorc.text = '''\
[Bootstrap]
URE_INTERNAL_LIB_DIR=file://$APP_DATA_DIR/lib/
UNO_TYPES=file://$APP_DATA_DIR/program/udkapi.rdb file://$APP_DATA_DIR/program/offapi.rdb file://$APP_DATA_DIR/program/oovbaapi.rdb
UNO_SERVICES=file:///assets/program/services.rdb file:///assets/program/services/services.rdb
'''.stripIndent()

        lounorc.text = '''\
[Bootstrap]
PKG_BundledUnoFile=$BUNDLED_EXTENSIONS_USER/registry/com.sun.star.comp.deployment.component.PackageRegistryBackend/unorc
PKG_SharedUnoFile=$SHARED_EXTENSIONS_USER/registry/com.sun.star.comp.deployment.component.PackageRegistryBackend/unorc
PKG_UserUnoFile=$UNO_USER_PACKAGES_CACHE/registry/com.sun.star.comp.deployment.component.PackageRegistryBackend/unorc
BAK_EXTENSIONS=${$BRAND_BASE_DIR/program/bootstraprc:UserInstallation}/user/extensions/bak
BUNDLED_EXTENSIONS=${$BRAND_BASE_DIR/program/bootstraprc:UserInstallation}/share/extensions
BUNDLED_EXTENSIONS_USER=${$BRAND_BASE_DIR/program/bootstraprc:UserInstallation}/user/extensions/bundled
TMP_EXTENSIONS=${$BRAND_BASE_DIR/program/bootstraprc:UserInstallation}/user/extensions/tmp
SHARED_EXTENSIONS_USER=${$BRAND_BASE_DIR/program/bootstraprc:UserInstallation}/user/extensions/shared
UNO_SHARED_PACKAGES=${$BRAND_BASE_DIR/program/bootstraprc:UserInstallation}/share/uno_packages
UNO_SHARED_PACKAGES_CACHE=$UNO_SHARED_PACKAGES/cache
UNO_USER_PACKAGES=${$BRAND_BASE_DIR/program/bootstraprc:UserInstallation}/user/uno_packages
UNO_USER_PACKAGES_CACHE=$UNO_USER_PACKAGES/cache
'''.stripIndent()

        versionrc.text = '''\
[Version]
AllLanguages=en-US
BuildVersion=
buildid=''' + "${liboGitFullCommit}" + '''
ReferenceOOoMajorMinor=4.1
'''.stripIndent()
    }
}

// creating the UI stuff is cheap, don't bother only applying it for the flavor..
preBuild.dependsOn 'createRCfiles',
        'createFullConfig'