build.gradle.kts 50 KB

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