build.gradle.kts 51 KB

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