build.gradle.kts 51 KB

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