build.gradle.kts 48 KB

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