build.gradle.kts 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. /* _____ _
  2. * |_ _| |_ _ _ ___ ___ _ __ __ _
  3. * | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. * |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. *
  6. * Threema for Android
  7. * Copyright (c) 2014-2025 Threema GmbH
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. import com.android.build.gradle.internal.api.ApkVariantOutputImpl
  22. import com.android.build.gradle.internal.tasks.factory.dependsOn
  23. import config.BuildFeatureFlags
  24. import config.PublicKeys
  25. import config.setProductNames
  26. import org.gradle.api.tasks.testing.logging.TestExceptionFormat
  27. import org.gradle.kotlin.dsl.lintChecks
  28. import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
  29. import utils.*
  30. plugins {
  31. alias(libs.plugins.sonarqube)
  32. alias(libs.plugins.kotlin.serialization)
  33. alias(libs.plugins.rust.android)
  34. id("com.android.application")
  35. id("kotlin-android")
  36. alias(libs.plugins.ksp)
  37. alias(libs.plugins.compose.compiler)
  38. alias(libs.plugins.stem)
  39. }
  40. // only apply the plugin if we are dealing with an AppGallery build
  41. if (gradle.startParameter.taskRequests.toString().contains("Hms")) {
  42. logger.info("enabling hms plugin")
  43. apply {
  44. plugin("com.huawei.agconnect")
  45. }
  46. }
  47. /**
  48. * Only use the scheme "<major>.<minor>.<patch>" for the appVersion
  49. */
  50. val appVersion = "6.3.1"
  51. /**
  52. * betaSuffix with leading dash (e.g. `-beta1`).
  53. * Should be one of (alpha|beta|rc) and an increasing number, or empty for a regular release.
  54. * Note: in nightly builds this will be overwritten with a nightly version "-n12345"
  55. */
  56. val betaSuffix = ""
  57. val defaultVersionCode = 1116
  58. /**
  59. * Map with keystore paths (if found).
  60. */
  61. val keystores: Map<String, KeystoreConfig?> = mapOf(
  62. "debug" to findKeystore(projectDir, "debug"),
  63. "release" to findKeystore(projectDir, "threema"),
  64. "hms_release" to findKeystore(projectDir, "threema_hms"),
  65. "onprem_release" to findKeystore(projectDir, "onprem"),
  66. "blue_release" to findKeystore(projectDir, "threema_blue"),
  67. )
  68. android {
  69. // NOTE: When adjusting compileSdkVersion, buildToolsVersion or ndkVersion,
  70. // make sure to adjust them in `scripts/Dockerfile` as well!
  71. compileSdk = 35
  72. buildToolsVersion = "35.0.0"
  73. ndkVersion = "28.2.13676358"
  74. defaultConfig {
  75. // https://developer.android.com/training/testing/espresso/setup#analytics
  76. with(testInstrumentationRunnerArguments) {
  77. put("notAnnotation", "ch.threema.app.DangerousTest")
  78. put("disableAnalytics", "true")
  79. }
  80. minSdk = 24
  81. targetSdk = 35
  82. vectorDrawables.useSupportLibrary = true
  83. applicationId = "ch.threema.app"
  84. testApplicationId = "$applicationId.test"
  85. versionCode = defaultVersionCode
  86. versionName = "$appVersion$betaSuffix"
  87. setProductNames(
  88. appName = "Threema",
  89. )
  90. intBuildConfigField("DEFAULT_VERSION_CODE", defaultVersionCode)
  91. // package name used for sync adapter - needs to match mime types below
  92. stringResValue("package_name", applicationId!!)
  93. stringResValue("contacts_mime_type", "vnd.android.cursor.item/vnd.$applicationId.profile")
  94. stringResValue("call_mime_type", "vnd.android.cursor.item/vnd.$applicationId.call")
  95. intBuildConfigField("MAX_GROUP_SIZE", 256)
  96. stringBuildConfigField("CHAT_SERVER_PREFIX", "g-")
  97. stringBuildConfigField("CHAT_SERVER_IPV6_PREFIX", "ds.g-")
  98. stringBuildConfigField("CHAT_SERVER_SUFFIX", ".0.threema.ch")
  99. intArrayBuildConfigField("CHAT_SERVER_PORTS", intArrayOf(5222, 443))
  100. stringBuildConfigField("MEDIA_PATH", "Threema")
  101. booleanBuildConfigField("CHAT_SERVER_GROUPS", true)
  102. booleanBuildConfigField("DISABLE_CERT_PINNING", false)
  103. booleanBuildConfigField("VIDEO_CALLS_ENABLED", true)
  104. // This public key is pinned for the chat server protocol.
  105. byteArrayBuildConfigField("SERVER_PUBKEY", PublicKeys.prodServer)
  106. byteArrayBuildConfigField("SERVER_PUBKEY_ALT", PublicKeys.prodServerAlt)
  107. stringBuildConfigField("GIT_HASH", getGitHash())
  108. stringBuildConfigField("GIT_BRANCH", getGitBranch())
  109. stringBuildConfigField("DIRECTORY_SERVER_URL", "https://apip.threema.ch/")
  110. stringBuildConfigField("DIRECTORY_SERVER_IPV6_URL", "https://ds-apip.threema.ch/")
  111. stringBuildConfigField("WORK_SERVER_URL", null)
  112. stringBuildConfigField("WORK_SERVER_IPV6_URL", null)
  113. stringBuildConfigField("MEDIATOR_SERVER_URL", "wss://mediator-{deviceGroupIdPrefix4}.threema.ch/{deviceGroupIdPrefix8}")
  114. // Base blob url used for "download" and "done" calls
  115. stringBuildConfigField("BLOB_SERVER_URL", "https://blobp-{blobIdPrefix}.threema.ch")
  116. stringBuildConfigField("BLOB_SERVER_IPV6_URL", "https://ds-blobp-{blobIdPrefix}.threema.ch")
  117. // Specific blob url used for "upload" calls
  118. stringBuildConfigField("BLOB_SERVER_URL_UPLOAD", "https://blobp-upload.threema.ch/upload")
  119. stringBuildConfigField("BLOB_SERVER_IPV6_URL_UPLOAD", "https://ds-blobp-upload.threema.ch/upload")
  120. // Base blob mirror url used for "download", "upload", "done"
  121. stringBuildConfigField("BLOB_MIRROR_SERVER_URL", "https://blob-mirror-{deviceGroupIdPrefix4}.threema.ch/{deviceGroupIdPrefix8}")
  122. stringBuildConfigField("AVATAR_FETCH_URL", "https://avatar.threema.ch/")
  123. stringBuildConfigField("SAFE_SERVER_URL", "https://safe-{backupIdPrefix8}.threema.ch/")
  124. stringBuildConfigField("WEB_SERVER_URL", "https://web.threema.ch/")
  125. stringBuildConfigField("APP_RATING_URL", "https://threema.com/app-rating/android/{rating}")
  126. stringBuildConfigField("MAP_STYLES_URL", "https://map.threema.ch/styles/threema/style.json")
  127. stringBuildConfigField("MAP_POI_AROUND_URL", "https://poi.threema.ch/around/{latitude}/{longitude}/{radius}/")
  128. stringBuildConfigField("MAP_POI_NAMES_URL", "https://poi.threema.ch/names/{latitude}/{longitude}/{query}/")
  129. byteArrayBuildConfigField("THREEMA_PUSH_PUBLIC_KEY", PublicKeys.threemaPush)
  130. stringBuildConfigField("ONPREM_ID_PREFIX", "O")
  131. stringBuildConfigField("LOG_TAG", "3ma")
  132. stringBuildConfigField("DEFAULT_APP_THEME", "2")
  133. stringArrayBuildConfigField("ONPREM_CONFIG_TRUSTED_PUBLIC_KEYS", emptyArray())
  134. booleanBuildConfigField("MD_SYNC_DISTRIBUTION_LISTS", false)
  135. booleanBuildConfigField("AVAILABILITY_STATUS_ENABLED", BuildFeatureFlags["availability_status"] ?: false)
  136. booleanBuildConfigField("CRASH_REPORTING_SUPPORTED", BuildFeatureFlags["crash_reporting"] ?: false)
  137. // config fields for action URLs / deep links
  138. stringBuildConfigField("uriScheme", "threema")
  139. stringBuildConfigField("actionUrl", "go.threema.ch")
  140. stringBuildConfigField("contactActionUrl", "threema.id")
  141. // The OPPF url must be null in the default config. Do not change this.
  142. stringBuildConfigField("PRESET_OPPF_URL", null)
  143. with(manifestPlaceholders) {
  144. put("uriScheme", "threema")
  145. put("contactActionUrl", "threema.id")
  146. put("actionUrl", "go.threema.ch")
  147. put("callMimeType", "vnd.android.cursor.item/vnd.$applicationId.call")
  148. }
  149. testInstrumentationRunner = "$applicationId.ThreemaTestRunner"
  150. // Only include language resources for those languages
  151. androidResources.localeFilters.addAll(
  152. setOf(
  153. "en",
  154. "be-rBY",
  155. "bg",
  156. "ca",
  157. "cs",
  158. "de",
  159. "es",
  160. "fr",
  161. "gsw",
  162. "hu",
  163. "it",
  164. "ja",
  165. "nl-rNL",
  166. "no",
  167. "pl",
  168. "pt-rBR",
  169. "ru",
  170. "sk",
  171. "tr",
  172. "uk",
  173. "zh-rCN",
  174. "zh-rTW",
  175. ),
  176. )
  177. }
  178. splits {
  179. abi {
  180. isEnable = true
  181. reset()
  182. if (project.hasProperty("noAbiSplits")) {
  183. isUniversalApk = true
  184. } else {
  185. include("armeabi-v7a", "x86", "arm64-v8a", "x86_64")
  186. isUniversalApk = project.hasProperty("buildUniversalApk")
  187. }
  188. }
  189. }
  190. // Assign different version code for each output
  191. android.applicationVariants.all {
  192. outputs.all {
  193. if (this is ApkVariantOutputImpl) {
  194. val abi = getFilter("ABI")
  195. val abiVersionCode = when (abi) {
  196. "armeabi-v7a" -> 2
  197. "arm64-v8a" -> 3
  198. "x86" -> 8
  199. "x86_64" -> 9
  200. else -> 0
  201. }
  202. versionCodeOverride = abiVersionCode * 1_000_000 + defaultVersionCode
  203. }
  204. }
  205. }
  206. namespace = "ch.threema.app"
  207. flavorDimensions.add("default")
  208. productFlavors {
  209. create("none")
  210. create("store_google")
  211. create("store_threema") {
  212. stringResValue("shop_download_filename", "Threema-update.apk")
  213. }
  214. create("store_google_work") {
  215. versionName = "${appVersion}k$betaSuffix"
  216. applicationId = "ch.threema.app.work"
  217. testApplicationId = "$applicationId.test"
  218. setProductNames(appName = "Threema Work")
  219. stringResValue("package_name", applicationId!!)
  220. stringResValue("contacts_mime_type", "vnd.android.cursor.item/vnd.$applicationId.profile")
  221. stringResValue("call_mime_type", "vnd.android.cursor.item/vnd.$applicationId.call")
  222. stringBuildConfigField("CHAT_SERVER_PREFIX", "w-")
  223. stringBuildConfigField("CHAT_SERVER_IPV6_PREFIX", "ds.w-")
  224. stringBuildConfigField("MEDIA_PATH", "ThreemaWork")
  225. stringBuildConfigField("WORK_SERVER_URL", "https://apip-work.threema.ch/")
  226. stringBuildConfigField("WORK_SERVER_IPV6_URL", "https://ds-apip-work.threema.ch/")
  227. stringBuildConfigField("APP_RATING_URL", "https://threema.com/app-rating/android-work/{rating}")
  228. stringBuildConfigField("LOG_TAG", "3mawrk")
  229. stringBuildConfigField("DEFAULT_APP_THEME", "2")
  230. // config fields for action URLs / deep links
  231. stringBuildConfigField("uriScheme", "threemawork")
  232. stringBuildConfigField("actionUrl", "work.threema.ch")
  233. with(manifestPlaceholders) {
  234. put("uriScheme", "threemawork")
  235. put("actionUrl", "work.threema.ch")
  236. put("callMimeType", "vnd.android.cursor.item/vnd.$applicationId.call")
  237. }
  238. }
  239. create("green") {
  240. applicationId = "ch.threema.app.green"
  241. testApplicationId = "$applicationId.test"
  242. setProductNames(appName = "Threema Green")
  243. stringResValue("package_name", applicationId!!)
  244. stringResValue("contacts_mime_type", "vnd.android.cursor.item/vnd.$applicationId.profile")
  245. stringResValue("call_mime_type", "vnd.android.cursor.item/vnd.$applicationId.call")
  246. stringBuildConfigField("MEDIA_PATH", "ThreemaGreen")
  247. stringBuildConfigField("CHAT_SERVER_SUFFIX", ".0.test.threema.ch")
  248. // This public key is pinned for the chat server protocol.
  249. byteArrayBuildConfigField("SERVER_PUBKEY", PublicKeys.sandboxServer)
  250. byteArrayBuildConfigField("SERVER_PUBKEY_ALT", PublicKeys.sandboxServer)
  251. stringBuildConfigField("DIRECTORY_SERVER_URL", "https://apip.test.threema.ch/")
  252. stringBuildConfigField("DIRECTORY_SERVER_IPV6_URL", "https://ds-apip.test.threema.ch/")
  253. stringBuildConfigField("MEDIATOR_SERVER_URL", "wss://mediator-{deviceGroupIdPrefix4}.test.threema.ch/{deviceGroupIdPrefix8}")
  254. stringBuildConfigField("BLOB_SERVER_URL", "https://blobp-{blobIdPrefix}.test.threema.ch")
  255. stringBuildConfigField("BLOB_SERVER_IPV6_URL", "https://ds-blobp-{blobIdPrefix}.test.threema.ch")
  256. stringBuildConfigField("BLOB_SERVER_URL_UPLOAD", "https://blobp-upload.test.threema.ch/upload")
  257. stringBuildConfigField("BLOB_SERVER_IPV6_URL_UPLOAD", "https://ds-blobp-upload.test.threema.ch/upload")
  258. stringBuildConfigField("AVATAR_FETCH_URL", "https://avatar.test.threema.ch/")
  259. stringBuildConfigField("APP_RATING_URL", "https://test.threema.com/app-rating/android/{rating}")
  260. stringBuildConfigField("MAP_STYLES_URL", "https://map.test.threema.ch/styles/threema/style.json")
  261. stringBuildConfigField("MAP_POI_AROUND_URL", "https://poi.test.threema.ch/around/{latitude}/{longitude}/{radius}/")
  262. stringBuildConfigField("MAP_POI_NAMES_URL", "https://poi.test.threema.ch/names/{latitude}/{longitude}/{query}/")
  263. stringBuildConfigField("BLOB_MIRROR_SERVER_URL", "https://blob-mirror-{deviceGroupIdPrefix4}.test.threema.ch/{deviceGroupIdPrefix8}")
  264. booleanBuildConfigField("CRASH_REPORTING_SUPPORTED", true)
  265. }
  266. create("sandbox_work") {
  267. versionName = "${appVersion}k$betaSuffix"
  268. applicationId = "ch.threema.app.sandbox.work"
  269. testApplicationId = "$applicationId.test"
  270. setProductNames(
  271. appName = "Threema Sandbox Work",
  272. appNameDesktop = "Threema Blue",
  273. )
  274. stringResValue("package_name", applicationId!!)
  275. stringResValue("contacts_mime_type", "vnd.android.cursor.item/vnd.$applicationId.profile")
  276. stringResValue("call_mime_type", "vnd.android.cursor.item/vnd.$applicationId.call")
  277. stringBuildConfigField("CHAT_SERVER_PREFIX", "w-")
  278. stringBuildConfigField("CHAT_SERVER_IPV6_PREFIX", "ds.w-")
  279. stringBuildConfigField("CHAT_SERVER_SUFFIX", ".0.test.threema.ch")
  280. stringBuildConfigField("MEDIA_PATH", "ThreemaWorkSandbox")
  281. // This public key is pinned for the chat server protocol.
  282. byteArrayBuildConfigField("SERVER_PUBKEY", PublicKeys.sandboxServer)
  283. byteArrayBuildConfigField("SERVER_PUBKEY_ALT", PublicKeys.sandboxServer)
  284. stringBuildConfigField("DIRECTORY_SERVER_URL", "https://apip.test.threema.ch/")
  285. stringBuildConfigField("DIRECTORY_SERVER_IPV6_URL", "https://ds-apip.test.threema.ch/")
  286. stringBuildConfigField("WORK_SERVER_URL", "https://apip-work.test.threema.ch/")
  287. stringBuildConfigField("WORK_SERVER_IPV6_URL", "https://ds-apip-work.test.threema.ch/")
  288. stringBuildConfigField("MEDIATOR_SERVER_URL", "wss://mediator-{deviceGroupIdPrefix4}.test.threema.ch/{deviceGroupIdPrefix8}")
  289. stringBuildConfigField("BLOB_SERVER_URL", "https://blobp-{blobIdPrefix}.test.threema.ch")
  290. stringBuildConfigField("BLOB_SERVER_IPV6_URL", "https://ds-blobp-{blobIdPrefix}.test.threema.ch")
  291. stringBuildConfigField("BLOB_SERVER_URL_UPLOAD", "https://blobp-upload.test.threema.ch/upload")
  292. stringBuildConfigField("BLOB_SERVER_IPV6_URL_UPLOAD", "https://ds-blobp-upload.test.threema.ch/upload")
  293. stringBuildConfigField("AVATAR_FETCH_URL", "https://avatar.test.threema.ch/")
  294. stringBuildConfigField("APP_RATING_URL", "https://test.threema.com/app-rating/android-work/{rating}")
  295. stringBuildConfigField("MAP_STYLES_URL", "https://map.test.threema.ch/styles/threema/style.json")
  296. stringBuildConfigField("MAP_POI_AROUND_URL", "https://poi.test.threema.ch/around/{latitude}/{longitude}/{radius}/")
  297. stringBuildConfigField("MAP_POI_NAMES_URL", "https://poi.test.threema.ch/names/{latitude}/{longitude}/{query}/")
  298. stringBuildConfigField("LOG_TAG", "3mawrk")
  299. stringBuildConfigField("DEFAULT_APP_THEME", "2")
  300. stringBuildConfigField("BLOB_MIRROR_SERVER_URL", "https://blob-mirror-{deviceGroupIdPrefix4}.test.threema.ch/{deviceGroupIdPrefix8}")
  301. // config fields for action URLs / deep links
  302. stringBuildConfigField("uriScheme", "threemawork")
  303. stringBuildConfigField("actionUrl", "work.test.threema.ch")
  304. booleanBuildConfigField("CRASH_REPORTING_SUPPORTED", true)
  305. stringBuildConfigField("MD_CLIENT_DOWNLOAD_URL", "https://three.ma/mdw")
  306. with(manifestPlaceholders) {
  307. put("uriScheme", "threemawork")
  308. put("actionUrl", "work.test.threema.ch")
  309. }
  310. }
  311. create("onprem") {
  312. versionName = "${appVersion}o$betaSuffix"
  313. applicationId = "ch.threema.app.onprem"
  314. testApplicationId = "$applicationId.test"
  315. setProductNames(
  316. appName = "Threema OnPrem",
  317. shortAppName = "Threema",
  318. companyName = "Threema",
  319. )
  320. stringResValue("package_name", applicationId!!)
  321. stringResValue("contacts_mime_type", "vnd.android.cursor.item/vnd.$applicationId.profile")
  322. stringResValue("call_mime_type", "vnd.android.cursor.item/vnd.$applicationId.call")
  323. intBuildConfigField("MAX_GROUP_SIZE", 256)
  324. stringBuildConfigField("CHAT_SERVER_PREFIX", "")
  325. stringBuildConfigField("CHAT_SERVER_IPV6_PREFIX", "")
  326. stringBuildConfigField("CHAT_SERVER_SUFFIX", null)
  327. stringBuildConfigField("MEDIA_PATH", "ThreemaOnPrem")
  328. booleanBuildConfigField("CHAT_SERVER_GROUPS", false)
  329. byteArrayBuildConfigField("SERVER_PUBKEY", null)
  330. byteArrayBuildConfigField("SERVER_PUBKEY_ALT", null)
  331. stringBuildConfigField("DIRECTORY_SERVER_URL", null)
  332. stringBuildConfigField("DIRECTORY_SERVER_IPV6_URL", null)
  333. stringBuildConfigField("BLOB_SERVER_URL", null)
  334. stringBuildConfigField("BLOB_SERVER_IPV6_URL", null)
  335. stringBuildConfigField("BLOB_SERVER_URL_UPLOAD", null)
  336. stringBuildConfigField("BLOB_SERVER_IPV6_URL_UPLOAD", null)
  337. stringBuildConfigField("BLOB_MIRROR_SERVER_URL", null)
  338. stringArrayBuildConfigField("ONPREM_CONFIG_TRUSTED_PUBLIC_KEYS", PublicKeys.onPremTrusted)
  339. stringBuildConfigField("LOG_TAG", "3maop")
  340. // config fields for action URLs / deep links
  341. val uriScheme = "threemaonprem"
  342. val actionUrl = "onprem.threema.ch"
  343. stringBuildConfigField("uriScheme", uriScheme)
  344. stringBuildConfigField("actionUrl", actionUrl)
  345. stringBuildConfigField("PRESET_OPPF_URL", null)
  346. stringBuildConfigField("MD_CLIENT_DOWNLOAD_URL", "https://three.ma/mdo")
  347. with(manifestPlaceholders) {
  348. put("uriScheme", uriScheme)
  349. put("actionUrl", actionUrl)
  350. put("callMimeType", "vnd.android.cursor.item/vnd.$applicationId.call")
  351. }
  352. }
  353. create("blue") {
  354. // Essentially like sandbox work, but with a different icon and application id, used for internal testing
  355. versionName = "${appVersion}b$betaSuffix"
  356. // The app was previously named `red`. The app id remains unchanged to still be able to install updates.
  357. applicationId = "ch.threema.app.red"
  358. testApplicationId = "ch.threema.app.blue.test"
  359. setProductNames(appName = "Threema Blue")
  360. stringResValue("package_name", applicationId!!)
  361. stringResValue("contacts_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.blue.profile")
  362. stringResValue("call_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.blue.call")
  363. stringBuildConfigField("CHAT_SERVER_PREFIX", "w-")
  364. stringBuildConfigField("CHAT_SERVER_IPV6_PREFIX", "ds.w-")
  365. stringBuildConfigField("CHAT_SERVER_SUFFIX", ".0.test.threema.ch")
  366. stringBuildConfigField("MEDIA_PATH", "ThreemaBlue")
  367. // This public key is pinned for the chat server protocol.
  368. byteArrayBuildConfigField("SERVER_PUBKEY", PublicKeys.sandboxServer)
  369. byteArrayBuildConfigField("SERVER_PUBKEY_ALT", PublicKeys.sandboxServer)
  370. stringBuildConfigField("DIRECTORY_SERVER_URL", "https://apip.test.threema.ch/")
  371. stringBuildConfigField("DIRECTORY_SERVER_IPV6_URL", "https://ds-apip.test.threema.ch/")
  372. stringBuildConfigField("WORK_SERVER_URL", "https://apip-work.test.threema.ch/")
  373. stringBuildConfigField("WORK_SERVER_IPV6_URL", "https://ds-apip-work.test.threema.ch/")
  374. stringBuildConfigField("MEDIATOR_SERVER_URL", "wss://mediator-{deviceGroupIdPrefix4}.test.threema.ch/{deviceGroupIdPrefix8}")
  375. stringBuildConfigField("BLOB_SERVER_URL", "https://blobp-{blobIdPrefix}.test.threema.ch")
  376. stringBuildConfigField("BLOB_SERVER_IPV6_URL", "https://ds-blobp-{blobIdPrefix}.test.threema.ch")
  377. stringBuildConfigField("BLOB_SERVER_URL_UPLOAD", "https://blobp-upload.test.threema.ch/upload")
  378. stringBuildConfigField("BLOB_SERVER_IPV6_URL_UPLOAD", "https://ds-blobp-upload.test.threema.ch/upload")
  379. stringBuildConfigField("AVATAR_FETCH_URL", "https://avatar.test.threema.ch/")
  380. stringBuildConfigField("APP_RATING_URL", "https://test.threema.com/app-rating/android-work/{rating}")
  381. stringBuildConfigField("MAP_STYLES_URL", "https://map.test.threema.ch/styles/threema/style.json")
  382. stringBuildConfigField("MAP_POI_AROUND_URL", "https://poi.test.threema.ch/around/{latitude}/{longitude}/{radius}/")
  383. stringBuildConfigField("MAP_POI_NAMES_URL", "https://poi.test.threema.ch/names/{latitude}/{longitude}/{query}/")
  384. stringBuildConfigField("LOG_TAG", "3mablue")
  385. stringBuildConfigField("BLOB_MIRROR_SERVER_URL", "https://blob-mirror-{deviceGroupIdPrefix4}.test.threema.ch/{deviceGroupIdPrefix8}")
  386. booleanBuildConfigField("CRASH_REPORTING_SUPPORTED", true)
  387. // config fields for action URLs / deep links
  388. stringBuildConfigField("uriScheme", "threemablue")
  389. stringBuildConfigField("actionUrl", "blue.threema.ch")
  390. with(manifestPlaceholders) {
  391. put("uriScheme", "threemablue")
  392. put("actionUrl", "blue.threema.ch")
  393. put("callMimeType", "vnd.android.cursor.item/vnd.ch.threema.app.blue.call")
  394. }
  395. }
  396. create("hms") {
  397. applicationId = "ch.threema.app.hms"
  398. }
  399. create("hms_work") {
  400. versionName = "${appVersion}k$betaSuffix"
  401. applicationId = "ch.threema.app.work.hms"
  402. testApplicationId = "ch.threema.app.work.test.hms"
  403. setProductNames(appName = "Threema Work")
  404. stringResValue("package_name", "ch.threema.app.work")
  405. stringResValue("contacts_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.work.profile")
  406. stringResValue("call_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.work.call")
  407. stringBuildConfigField("CHAT_SERVER_PREFIX", "w-")
  408. stringBuildConfigField("CHAT_SERVER_IPV6_PREFIX", "ds.w-")
  409. stringBuildConfigField("MEDIA_PATH", "ThreemaWork")
  410. stringBuildConfigField("WORK_SERVER_URL", "https://apip-work.threema.ch/")
  411. stringBuildConfigField("WORK_SERVER_IPV6_URL", "https://ds-apip-work.threema.ch/")
  412. stringBuildConfigField("APP_RATING_URL", "https://threema.com/app-rating/android-work/{rating}")
  413. stringBuildConfigField("LOG_TAG", "3mawrk")
  414. stringBuildConfigField("DEFAULT_APP_THEME", "2")
  415. // config fields for action URLs / deep links
  416. stringBuildConfigField("uriScheme", "threemawork")
  417. stringBuildConfigField("actionUrl", "work.threema.ch")
  418. with(manifestPlaceholders) {
  419. put("uriScheme", "threemawork")
  420. put("actionUrl", "work.threema.ch")
  421. put("callMimeType", "vnd.android.cursor.item/vnd.ch.threema.app.work.call")
  422. }
  423. }
  424. create("libre") {
  425. versionName = "${appVersion}l$betaSuffix"
  426. applicationId = "ch.threema.app.libre"
  427. testApplicationId = "$applicationId.test"
  428. stringResValue("package_name", applicationId!!)
  429. setProductNames(
  430. appName = "Threema Libre",
  431. appNameDesktop = "Threema",
  432. )
  433. stringBuildConfigField("MEDIA_PATH", "ThreemaLibre")
  434. }
  435. }
  436. signingConfigs {
  437. // Debug config
  438. keystores["debug"]
  439. ?.let { keystore ->
  440. getByName("debug") {
  441. storeFile = keystore.storeFile
  442. }
  443. }
  444. ?: run {
  445. logger.warn("No debug keystore found. Falling back to locally generated keystore.")
  446. }
  447. // Release config
  448. keystores["release"]
  449. ?.let { keystore ->
  450. create("release") {
  451. apply(keystore)
  452. }
  453. }
  454. ?: run {
  455. logger.warn("No release keystore found. Falling back to locally generated keystore.")
  456. }
  457. // Release config
  458. keystores["hms_release"]
  459. ?.let { keystore ->
  460. create("hms_release") {
  461. apply(keystore)
  462. }
  463. }
  464. ?: run {
  465. logger.warn("No hms keystore found. Falling back to locally generated keystore.")
  466. }
  467. // Onprem release config
  468. keystores["onprem_release"]
  469. ?.let { keystore ->
  470. create("onprem_release") {
  471. apply(keystore)
  472. }
  473. }
  474. ?: run {
  475. logger.warn("No onprem keystore found. Falling back to locally generated keystore.")
  476. }
  477. // Blue release config
  478. keystores["blue_release"]
  479. ?.let { keystore ->
  480. create("blue_release") {
  481. apply(keystore)
  482. }
  483. }
  484. ?: run {
  485. logger.warn("No blue keystore found. Falling back to locally generated keystore.")
  486. }
  487. // Note: Libre release is signed with HSM, no config here
  488. }
  489. sourceSets {
  490. getByName("main") {
  491. assets.srcDirs("assets")
  492. jniLibs.srcDirs("libs")
  493. res.srcDir("src/main/res-rendezvous")
  494. java.srcDir("./build/generated/source/protobuf/main/java")
  495. java.srcDir("./build/generated/source/protobuf/main/kotlin")
  496. }
  497. // Based on Google services
  498. getByName("none") {
  499. java.srcDir("src/google_services_based/java")
  500. }
  501. getByName("store_google") {
  502. java.srcDir("src/google_services_based/java")
  503. }
  504. getByName("store_google_work") {
  505. java.srcDir("src/google_services_based/java")
  506. }
  507. getByName("store_threema") {
  508. java.srcDir("src/google_services_based/java")
  509. }
  510. getByName("libre") {
  511. assets.srcDirs("src/foss_based/assets")
  512. java.srcDir("src/foss_based/java")
  513. }
  514. getByName("onprem") {
  515. java.srcDir("src/google_services_based/java")
  516. }
  517. getByName("green") {
  518. java.srcDir("src/google_services_based/java")
  519. manifest.srcFile("src/store_google/AndroidManifest.xml")
  520. }
  521. getByName("sandbox_work") {
  522. java.srcDir("src/google_services_based/java")
  523. res.srcDir("src/store_google_work/res")
  524. manifest.srcFile("src/store_google_work/AndroidManifest.xml")
  525. }
  526. getByName("blue") {
  527. java.srcDir("src/google_services_based/java")
  528. res.srcDir("src/blue/res")
  529. }
  530. // Based on Huawei services
  531. getByName("hms") {
  532. java.srcDir("src/hms_services_based/java")
  533. }
  534. getByName("hms_work") {
  535. java.srcDir("src/hms_services_based/java")
  536. res.srcDir("src/store_google_work/res")
  537. }
  538. // FOSS, no proprietary services
  539. getByName("libre") {
  540. assets.srcDirs("src/foss_based/assets")
  541. java.srcDir("src/foss_based/java")
  542. }
  543. }
  544. buildTypes {
  545. debug {
  546. isDebuggable = true
  547. ndk {
  548. debugSymbolLevel = "FULL"
  549. }
  550. enableUnitTestCoverage = false
  551. enableAndroidTestCoverage = false
  552. if (keystores["debug"] != null) {
  553. signingConfig = signingConfigs["debug"]
  554. }
  555. }
  556. release {
  557. isDebuggable = false
  558. isMinifyEnabled = true
  559. isShrinkResources = false // Caused inconsistencies between local and CI builds
  560. vcsInfo.include = false // For reproducible builds independent from git history
  561. proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-project.txt")
  562. ndk {
  563. debugSymbolLevel = "FULL" // 'SYMBOL_TABLE'
  564. }
  565. if (keystores["release"] != null) {
  566. val releaseSigningConfig = signingConfigs["release"]
  567. productFlavors["store_google"].signingConfig = releaseSigningConfig
  568. productFlavors["store_google_work"].signingConfig = releaseSigningConfig
  569. productFlavors["store_threema"].signingConfig = releaseSigningConfig
  570. productFlavors["green"].signingConfig = releaseSigningConfig
  571. productFlavors["sandbox_work"].signingConfig = releaseSigningConfig
  572. productFlavors["none"].signingConfig = releaseSigningConfig
  573. }
  574. if (keystores["hms_release"] != null) {
  575. val hmsReleaseSigningConfig = signingConfigs["hms_release"]
  576. productFlavors["hms"].signingConfig = hmsReleaseSigningConfig
  577. productFlavors["hms_work"].signingConfig = hmsReleaseSigningConfig
  578. }
  579. if (keystores["onprem_release"] != null) {
  580. productFlavors["onprem"].signingConfig = signingConfigs["onprem_release"]
  581. }
  582. if (keystores["blue_release"] != null) {
  583. productFlavors["blue"].signingConfig = signingConfigs["blue_release"]
  584. }
  585. // Note: Libre release is signed with HSM, no config here
  586. }
  587. }
  588. packaging {
  589. jniLibs {
  590. // replacement for extractNativeLibs in AndroidManifest
  591. useLegacyPackaging = true
  592. }
  593. resources {
  594. excludes.addAll(
  595. setOf(
  596. "META-INF/DEPENDENCIES.txt",
  597. "META-INF/LICENSE.txt",
  598. "META-INF/LICENSE.md",
  599. "META-INF/LICENSE-notice.md",
  600. "META-INF/NOTICE.txt",
  601. "META-INF/NOTICE",
  602. "META-INF/LICENSE",
  603. "META-INF/DEPENDENCIES",
  604. "META-INF/notice.txt",
  605. "META-INF/license.txt",
  606. "META-INF/dependencies.txt",
  607. "META-INF/LGPL2.1",
  608. "**/*.proto",
  609. "DebugProbesKt.bin",
  610. ),
  611. )
  612. }
  613. }
  614. testOptions {
  615. // Disable animations in instrumentation tests
  616. animationsDisabled = true
  617. unitTests {
  618. all { test ->
  619. test.outputs.upToDateWhen { false }
  620. test.testLogging {
  621. events("passed", "skipped", "failed", "standardOut", "standardError")
  622. exceptionFormat = TestExceptionFormat.FULL
  623. }
  624. test.jvmArgs = test.jvmArgs!! + listOf(
  625. "--add-opens=java.base/java.util=ALL-UNNAMED",
  626. "--add-opens=java.base/java.util.stream=ALL-UNNAMED",
  627. "--add-opens=java.base/java.lang=ALL-UNNAMED",
  628. "-Xmx4096m",
  629. )
  630. }
  631. // By default, local unit tests throw an exception any time the code you are testing tries to access
  632. // Android platform APIs (unless you mock Android dependencies yourself or with a testing
  633. // framework like Mockk). However, you can enable the following property so that the test
  634. // returns either null or zero when accessing platform APIs, rather than throwing an exception.
  635. isReturnDefaultValues = true
  636. }
  637. }
  638. compileOptions {
  639. isCoreLibraryDesugaringEnabled = true
  640. sourceCompatibility = JavaVersion.VERSION_11
  641. targetCompatibility = JavaVersion.VERSION_11
  642. }
  643. java {
  644. toolchain {
  645. languageVersion.set(JavaLanguageVersion.of(17))
  646. }
  647. }
  648. kotlin {
  649. jvmToolchain(17)
  650. }
  651. androidResources {
  652. noCompress.add("png")
  653. }
  654. lint {
  655. // if true, stop the gradle build if errors are found
  656. abortOnError = true
  657. // if true, check all issues, including those that are off by default
  658. checkAllWarnings = true
  659. // check dependencies
  660. checkDependencies = true
  661. // set to true to have all release builds run lint on issues with severity=fatal
  662. // and abort the build (controlled by abortOnError above) if fatal issues are found
  663. checkReleaseBuilds = true
  664. // turn off checking the given issue id's
  665. disable.addAll(setOf("TypographyFractions", "TypographyQuotes", "RtlHardcoded", "RtlCompat", "RtlEnabled"))
  666. // Set the severity of the given issues to error
  667. error.addAll(setOf("Wakelock", "TextViewEdits", "ResourceAsColor"))
  668. // Set the severity of the given issues to fatal (which means they will be
  669. // checked during release builds (even if the lint target is not included)
  670. fatal.addAll(setOf("NewApi", "InlinedApi", "LoggerName"))
  671. ignoreWarnings = false
  672. // if true, don't include source code lines in the error output
  673. noLines = false
  674. // if true, show all locations for an error, do not truncate lists, etc.
  675. showAll = true
  676. // Set the severity of the given issues to warning
  677. warning.add("MissingTranslation")
  678. // if true, treat all warnings as errors
  679. warningsAsErrors = false
  680. // file to write report to (if not specified, defaults to lint-results.xml)
  681. xmlOutput = file("lint-report.xml")
  682. // if true, generate an XML report for use by for example Jenkins
  683. xmlReport = true
  684. }
  685. buildFeatures {
  686. compose = true
  687. buildConfig = true
  688. }
  689. }
  690. composeCompiler {
  691. includeSourceInformation = true
  692. stabilityConfigurationFiles.add(rootProject.layout.projectDirectory.file("stability_config.conf"))
  693. }
  694. // Only build relevant buildType / flavor combinations
  695. androidComponents {
  696. beforeVariants { variant ->
  697. val name = variant.name
  698. if (variant.buildType == "release" && ("green" in name || "sandbox_work" in name)) {
  699. variant.enable = false
  700. }
  701. }
  702. }
  703. dependencies {
  704. configurations.all {
  705. // Prefer modules that are part of this build (multi-project or composite build)
  706. // over external modules
  707. resolutionStrategy.preferProjectModules()
  708. // Alternatively, we can fail eagerly on version conflict to see the conflicts
  709. // resolutionStrategy.failOnVersionConflict()
  710. }
  711. coreLibraryDesugaring(libs.desugarJdkLibs)
  712. implementation(project(":domain"))
  713. implementation(project("::commonAndroid"))
  714. implementation(project(":common"))
  715. lintChecks(project(":lint-rules"))
  716. // Dependency Injection
  717. implementation(libs.koin.android)
  718. implementation(libs.koin.androidCompat)
  719. implementation(libs.koin.compose)
  720. testImplementation(libs.koin.test)
  721. testImplementation(libs.koin.test.junit4)
  722. implementation(libs.sqlcipher.android)
  723. implementation(libs.subsamplingScaleImageView)
  724. implementation(libs.opencsv)
  725. implementation(libs.zip4j)
  726. implementation(libs.taptargetview)
  727. implementation(libs.commonsIo)
  728. implementation(libs.slf4j.api)
  729. implementation(libs.androidImageCropper)
  730. implementation(libs.fastscroll)
  731. implementation(libs.ezVcard)
  732. implementation(libs.gestureViews)
  733. // AndroidX / Jetpack support libraries
  734. implementation(libs.androidx.preference)
  735. implementation(libs.androidx.recyclerview)
  736. implementation(libs.androidx.palette)
  737. implementation(libs.androidx.swiperefreshlayout)
  738. implementation(libs.androidx.core)
  739. implementation(libs.androidx.appcompat)
  740. implementation(libs.androidx.constraintlayout)
  741. implementation(libs.androidx.biometric)
  742. implementation(libs.androidx.work.runtime)
  743. implementation(libs.androidx.fragment)
  744. implementation(libs.androidx.activity)
  745. implementation(libs.androidx.sqlite)
  746. implementation(libs.androidx.concurrent.futures)
  747. implementation(libs.androidx.camera2)
  748. implementation(libs.androidx.camera.lifecycle)
  749. implementation(libs.androidx.camera.view)
  750. implementation(libs.androidx.camera.video)
  751. implementation(libs.androidx.media)
  752. implementation(libs.androidx.media3.exoplayer)
  753. implementation(libs.androidx.media3.ui)
  754. implementation(libs.androidx.media3.session)
  755. implementation(libs.androidx.lifecycle.viewmodel)
  756. implementation(libs.androidx.lifecycle.livedata)
  757. implementation(libs.androidx.lifecycle.runtime)
  758. implementation(libs.androidx.lifecycle.viewmodel.savedstate)
  759. implementation(libs.androidx.lifecycle.service)
  760. implementation(libs.androidx.lifecycle.process)
  761. implementation(libs.androidx.lifecycle.commonJava8)
  762. implementation(libs.androidx.lifecycle.extensions)
  763. implementation(libs.androidx.paging.runtime)
  764. implementation(libs.androidx.sharetarget)
  765. implementation(libs.androidx.room.runtime)
  766. implementation(libs.androidx.window)
  767. implementation(libs.androidx.splashscreen)
  768. ksp(libs.androidx.room.compiler)
  769. // Jetpack Compose
  770. implementation(platform(libs.compose.bom))
  771. implementation(libs.androidx.material3)
  772. implementation(libs.androidx.ui.tooling.preview)
  773. implementation(libs.androidx.activity.compose)
  774. implementation(libs.androidx.lifecycle.viewmodel.compose)
  775. implementation(libs.androidx.lifecycle.runtime.compose)
  776. debugImplementation(libs.androidx.ui.tooling)
  777. androidTestImplementation(platform(libs.compose.bom))
  778. implementation(libs.bcprov.jdk15to18)
  779. implementation(libs.material)
  780. implementation(libs.zxing)
  781. implementation(libs.libphonenumber)
  782. // webclient dependencies
  783. implementation(libs.msgpack.core)
  784. implementation(libs.jackson.core)
  785. implementation(libs.nvWebsocket.client)
  786. implementation(libs.streamsupport.cfuture)
  787. implementation(libs.saltyrtc.client) {
  788. exclude(group = "org.json")
  789. }
  790. implementation(libs.chunkedDc)
  791. implementation(libs.webrtcAndroid)
  792. implementation(libs.saltyrtc.taskWebrtc) {
  793. exclude(module = "saltyrtc-client")
  794. }
  795. // Glide components
  796. implementation(libs.glide)
  797. ksp(libs.glide.ksp)
  798. // Kotlin
  799. implementation(libs.kotlin.stdlib)
  800. implementation(libs.kotlinx.coroutines.android)
  801. implementation(libs.kotlinx.serialization.json)
  802. testImplementation(libs.kotlin.test)
  803. androidTestImplementation(libs.kotlin.test)
  804. // use leak canary in debug builds if requested
  805. if (project.hasProperty("leakCanary")) {
  806. debugImplementation(libs.leakcanary)
  807. }
  808. // test dependencies
  809. testImplementation(libs.junit)
  810. testImplementation(testFixtures(project(":domain")))
  811. // custom test helpers, shared between unit test and android tests
  812. testImplementation(project(":test-helpers"))
  813. androidTestImplementation(project(":test-helpers"))
  814. testImplementation(libs.mockk)
  815. androidTestImplementation(libs.mockkAndroid)
  816. // add JSON support to tests without mocking
  817. testImplementation(libs.json)
  818. testImplementation(libs.archunit.junit4)
  819. androidTestImplementation(testFixtures(project(":domain")))
  820. androidTestImplementation(libs.androidx.test.rules)
  821. androidTestImplementation(libs.fastlane.screengrab) {
  822. exclude(group = "androidx.annotation", module = "annotation")
  823. }
  824. androidTestImplementation(libs.androidx.espresso.core) {
  825. exclude(group = "androidx.annotation", module = "annotation")
  826. }
  827. androidTestImplementation(libs.androidx.test.runner) {
  828. exclude(group = "androidx.annotation", module = "annotation")
  829. }
  830. androidTestImplementation(libs.androidx.junit)
  831. androidTestImplementation(libs.androidx.espresso.contrib) {
  832. exclude(group = "androidx.annotation", module = "annotation")
  833. exclude(group = "androidx.appcompat", module = "appcompat")
  834. exclude(group = "androidx.legacy", module = "legacy-support-v4")
  835. exclude(group = "com.google.android.material", module = "material")
  836. exclude(group = "androidx.recyclerview", module = "recyclerview")
  837. exclude(group = "org.checkerframework", module = "checker")
  838. exclude(module = "protobuf-lite")
  839. }
  840. androidTestImplementation(libs.androidx.espresso.intents) {
  841. exclude(group = "androidx.annotation", module = "annotation")
  842. }
  843. androidTestImplementation(libs.androidx.test.uiautomator)
  844. androidTestImplementation(libs.androidx.test.core)
  845. androidTestImplementation(libs.kotlinx.coroutines.test)
  846. testImplementation(libs.kotlinx.coroutines.test)
  847. // Google Play Services and related libraries
  848. "noneImplementation"(libs.playServices.base)
  849. "store_googleImplementation"(libs.playServices.base)
  850. "store_google_workImplementation"(libs.playServices.base)
  851. "store_threemaImplementation"(libs.playServices.base)
  852. "onpremImplementation"(libs.playServices.base)
  853. "greenImplementation"(libs.playServices.base)
  854. "sandbox_workImplementation"(libs.playServices.base)
  855. "blueImplementation"(libs.playServices.base)
  856. fun ExternalModuleDependency.excludeFirebaseDependencies() {
  857. exclude(group = "com.google.firebase", module = "firebase-core")
  858. exclude(group = "com.google.firebase", module = "firebase-analytics")
  859. exclude(group = "com.google.firebase", module = "firebase-measurement-connector")
  860. }
  861. "noneImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  862. "store_googleImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  863. "store_google_workImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  864. "store_threemaImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  865. "onpremImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  866. "greenImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  867. "sandbox_workImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  868. "blueImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  869. // Google Assistant Voice Action verification library
  870. "noneImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  871. "store_googleImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  872. "store_google_workImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  873. "onpremImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  874. "store_threemaImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  875. "greenImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  876. "sandbox_workImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  877. "blueImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  878. // Maplibre (may have transitive dependencies on Google location services)
  879. "noneImplementation"(libs.maplibre)
  880. "store_googleImplementation"(libs.maplibre)
  881. "store_google_workImplementation"(libs.maplibre)
  882. "store_threemaImplementation"(libs.maplibre)
  883. "libreImplementation"(libs.maplibre) {
  884. exclude(group = "com.google.android.gms")
  885. }
  886. "onpremImplementation"(libs.maplibre)
  887. "greenImplementation"(libs.maplibre)
  888. "sandbox_workImplementation"(libs.maplibre)
  889. "blueImplementation"(libs.maplibre)
  890. "hmsImplementation"(libs.maplibre)
  891. "hms_workImplementation"(libs.maplibre)
  892. // Huawei related libraries (only for hms* build variants)
  893. // Exclude agconnect dependency, we'll replace it with the vendored version below
  894. "hmsImplementation"(libs.hmsPush) {
  895. exclude(group = "com.huawei.agconnect")
  896. }
  897. "hms_workImplementation"(libs.hmsPush) {
  898. exclude(group = "com.huawei.agconnect")
  899. }
  900. "hmsImplementation"(group = "", name = "agconnect-core-1.9.1.301", ext = "aar")
  901. "hms_workImplementation"(group = "", name = "agconnect-core-1.9.1.301", ext = "aar")
  902. }
  903. // Define the cargo attributes. These will be used by the rust-android plugin that will create the
  904. // 'cargoBuild' task that builds native libraries that will be added to the apk. Note that the
  905. // kotlin bindings are created in the domain module. Building native libraries with rust-android
  906. // cannot be done in any other module than 'app'.
  907. cargo {
  908. prebuiltToolchains = true
  909. targetDirectory = "$projectDir/build/generated/source/libthreema"
  910. module = "$projectDir/../domain/libthreema" // must contain Cargo.toml
  911. libname = "libthreema" // must match the Cargo.toml's package name
  912. profile = "release"
  913. pythonCommand = "python3"
  914. targets = listOf("x86_64", "arm64", "arm", "x86")
  915. features {
  916. defaultAnd(arrayOf("uniffi"))
  917. }
  918. extraCargoBuildArguments = listOf("--lib", "--target-dir", "$projectDir/build/generated/source/libthreema", "--locked")
  919. verbose = false
  920. }
  921. afterEvaluate {
  922. // The `cargoBuild` task isn't available until after evaluation.
  923. android.applicationVariants.configureEach {
  924. val variantName = name.replaceFirstChar { it.uppercase() }
  925. // Set the dependency so that cargoBuild is executed before the native libs are merged
  926. tasks["merge${variantName}NativeLibs"].dependsOn(tasks["cargoBuild"])
  927. }
  928. }
  929. sonarqube {
  930. properties {
  931. property(
  932. "sonar.sources",
  933. listOf(
  934. "src/main/",
  935. "../scripts/",
  936. "../scripts-internal/",
  937. )
  938. .joinToString(separator = ", "),
  939. )
  940. property(
  941. "sonar.exclusions",
  942. listOf(
  943. "src/**/res/",
  944. "src/**/res-rendezvous/",
  945. "**/emojis/EmojiParser.kt",
  946. "**/emojis/EmojiSpritemap.kt",
  947. )
  948. .joinToString(separator = ", "),
  949. )
  950. property("sonar.tests", "src/test/")
  951. property("sonar.sourceEncoding", "UTF-8")
  952. property("sonar.verbose", "true")
  953. property("sonar.projectKey", "android-client")
  954. property("sonar.projectName", "Threema for Android")
  955. }
  956. }
  957. androidStem {
  958. includeLocalizedOnlyTemplates = true
  959. }
  960. tasks.register<Exec>("compileProto") {
  961. group = "build"
  962. description = "generate class bindings from protobuf files in the 'protobuf' directory"
  963. workingDir(project.projectDir)
  964. commandLine("./compile-proto.sh")
  965. }
  966. project.tasks.preBuild.dependsOn("compileProto")
  967. tasks.withType<Test> {
  968. // Necessary to load the dynamic libthreema library in unit tests
  969. systemProperty("jna.library.path", "${project.projectDir}/../domain/libthreema/target/release")
  970. }
  971. // Set up Gradle tasks to fetch screenshots on UI test failures
  972. // See https://medium.com/stepstone-tech/how-to-capture-screenshots-for-failed-ui-tests-9927eea6e1e4
  973. val reportsDirectory = "${layout.buildDirectory}/reports/androidTests/connected"
  974. val screenshotsDirectory = "/sdcard/testfailures/screenshots/"
  975. val clearScreenshotsTask = tasks.register<Exec>("clearScreenshots") {
  976. executable = android.adbExecutable.toString()
  977. args("shell", "rm", "-r", screenshotsDirectory)
  978. }
  979. val createScreenshotsDirectoryTask = tasks.register<Exec>("createScreenshotsDirectory") {
  980. group = "reporting"
  981. executable = android.adbExecutable.toString()
  982. args("shell", "mkdir", "-p", screenshotsDirectory)
  983. }
  984. val fetchScreenshotsTask = tasks.register<Exec>("fetchScreenshots") {
  985. group = "reporting"
  986. executable = android.adbExecutable.toString()
  987. args("pull", "$screenshotsDirectory.", reportsDirectory)
  988. finalizedBy(clearScreenshotsTask)
  989. dependsOn(createScreenshotsDirectoryTask)
  990. doFirst {
  991. file(reportsDirectory).mkdirs()
  992. }
  993. }
  994. tasks.whenTaskAdded {
  995. if (name == "connectedDebugAndroidTest") {
  996. finalizedBy(fetchScreenshotsTask)
  997. }
  998. }
  999. // Let the compose compiler generate stability reports
  1000. tasks.withType<KotlinCompile>().configureEach {
  1001. compilerOptions {
  1002. val composeCompilerReportsPath = "${project.layout.buildDirectory.get().dir("compose_conpiler").asFile.absolutePath}/reports"
  1003. freeCompilerArgs.addAll(
  1004. listOf(
  1005. "-P",
  1006. "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=$composeCompilerReportsPath",
  1007. ),
  1008. )
  1009. }
  1010. }