build.gradle.kts 46 KB

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