build.gradle.kts 44 KB

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