build.gradle.kts 51 KB

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