build.gradle.kts 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  1. import com.android.build.gradle.internal.api.ApkVariantOutputImpl
  2. import com.android.build.gradle.internal.tasks.factory.dependsOn
  3. import config.PublicKeys
  4. import config.SentryConfig
  5. import config.setProductNames
  6. import config.setSentryConfig
  7. import org.gradle.api.tasks.testing.logging.TestExceptionFormat
  8. import org.gradle.kotlin.dsl.lintChecks
  9. import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
  10. import utils.*
  11. plugins {
  12. alias(libs.plugins.sonarqube)
  13. alias(libs.plugins.kotlin.serialization)
  14. alias(libs.plugins.rust.android)
  15. id("com.android.application")
  16. id("kotlin-android")
  17. alias(libs.plugins.ksp)
  18. alias(libs.plugins.compose.compiler)
  19. alias(libs.plugins.stem)
  20. }
  21. // only apply the plugin if we are dealing with an AppGallery build
  22. if (gradle.startParameter.taskRequests.toString().contains("Hms")) {
  23. logger.info("enabling hms plugin")
  24. apply {
  25. plugin("com.huawei.agconnect")
  26. }
  27. }
  28. /**
  29. * Only use the scheme "<major>.<minor>.<patch>" for the appVersion
  30. */
  31. val appVersion = "6.4.3"
  32. /**
  33. * betaSuffix with leading dash (e.g. `-beta1`).
  34. * Should be one of (alpha|beta|rc) and an increasing number, or empty for a regular release.
  35. * Note: in nightly builds this will be overwritten with a nightly version "-n12345"
  36. */
  37. val betaSuffix = ""
  38. val defaultVersionCode = 1148
  39. /**
  40. * Map with keystore paths (if found).
  41. */
  42. val keystores: Map<String, KeystoreConfig?> = mapOf(
  43. "debug" to findKeystore(projectDir, "debug"),
  44. "release" to findKeystore(projectDir, "threema"),
  45. "hms_release" to findKeystore(projectDir, "threema_hms"),
  46. "onprem_release" to findKeystore(projectDir, "onprem"),
  47. "blue_release" to findKeystore(projectDir, "threema_blue"),
  48. )
  49. android {
  50. // NOTE: When adjusting compileSdkVersion, buildToolsVersion or ndkVersion,
  51. // make sure to adjust them in `scripts/Dockerfile` as well!
  52. compileSdk = 35
  53. buildToolsVersion = "35.0.0"
  54. ndkVersion = "28.2.13676358"
  55. defaultConfig {
  56. // https://developer.android.com/training/testing/espresso/setup#analytics
  57. with(testInstrumentationRunnerArguments) {
  58. put("notAnnotation", "ch.threema.app.DangerousTest")
  59. put("disableAnalytics", "true")
  60. }
  61. minSdk = 24
  62. targetSdk = 35
  63. vectorDrawables.useSupportLibrary = true
  64. applicationId = "ch.threema.app"
  65. testApplicationId = "$applicationId.test"
  66. versionCode = defaultVersionCode
  67. versionName = "$appVersion$betaSuffix"
  68. setProductNames(
  69. appName = "Threema",
  70. )
  71. intBuildConfigField("DEFAULT_VERSION_CODE", defaultVersionCode)
  72. // package name used for sync adapter - needs to match mime types below
  73. stringResValue("package_name", applicationId!!)
  74. stringResValue("contacts_mime_type", "vnd.android.cursor.item/vnd.$applicationId.profile")
  75. stringResValue("call_mime_type", "vnd.android.cursor.item/vnd.$applicationId.call")
  76. intBuildConfigField("MAX_GROUP_SIZE", 256)
  77. stringBuildConfigField("CHAT_SERVER_PREFIX", "g-")
  78. stringBuildConfigField("CHAT_SERVER_IPV6_PREFIX", "ds.g-")
  79. stringBuildConfigField("CHAT_SERVER_SUFFIX", ".0.threema.ch")
  80. intArrayBuildConfigField("CHAT_SERVER_PORTS", intArrayOf(5222, 443))
  81. stringBuildConfigField("MEDIA_PATH", "Threema")
  82. booleanBuildConfigField("CHAT_SERVER_GROUPS", true)
  83. booleanBuildConfigField("DISABLE_CERT_PINNING", false)
  84. booleanBuildConfigField("VIDEO_CALLS_ENABLED", true)
  85. // This public key is pinned for the chat server protocol.
  86. byteArrayBuildConfigField("SERVER_PUBKEY", PublicKeys.prodServer)
  87. byteArrayBuildConfigField("SERVER_PUBKEY_ALT", PublicKeys.prodServerAlt)
  88. stringBuildConfigField("GIT_HASH", getGitHash())
  89. stringBuildConfigField("GIT_BRANCH", getGitBranch())
  90. stringBuildConfigField("DIRECTORY_SERVER_URL", "https://apip.threema.ch/")
  91. stringBuildConfigField("DIRECTORY_SERVER_IPV6_URL", "https://ds-apip.threema.ch/")
  92. stringBuildConfigField("WORK_SERVER_URL_LEGACY", null)
  93. stringBuildConfigField("WORK_SERVER_IPV6_URL_LEGACY", null)
  94. stringBuildConfigField("WORK_SERVER_URL", null)
  95. stringBuildConfigField("MEDIATOR_SERVER_URL", "wss://mediator-{deviceGroupIdPrefix4}.threema.ch/{deviceGroupIdPrefix8}/")
  96. // Base blob url used for "download" and "done" calls
  97. stringBuildConfigField("BLOB_SERVER_URL", "https://blobp-{blobIdPrefix}.threema.ch")
  98. stringBuildConfigField("BLOB_SERVER_IPV6_URL", "https://ds-blobp-{blobIdPrefix}.threema.ch")
  99. // Specific blob url used for "upload" calls
  100. stringBuildConfigField("BLOB_SERVER_URL_UPLOAD", "https://blobp-upload.threema.ch/upload")
  101. stringBuildConfigField("BLOB_SERVER_IPV6_URL_UPLOAD", "https://ds-blobp-upload.threema.ch/upload")
  102. // Base blob mirror url used for "download", "upload", "done"
  103. stringBuildConfigField("BLOB_MIRROR_SERVER_URL", "https://blob-mirror-{deviceGroupIdPrefix4}.threema.ch/{deviceGroupIdPrefix8}")
  104. stringBuildConfigField("AVATAR_FETCH_URL", "https://avatar.threema.ch/")
  105. stringBuildConfigField("SAFE_SERVER_URL", "https://safe-{backupIdPrefix8}.threema.ch/")
  106. stringBuildConfigField("WEB_SERVER_URL", "https://web.threema.ch/")
  107. stringBuildConfigField("APP_RATING_URL", "https://threema.com/app-rating/android/{rating}")
  108. stringBuildConfigField("MAP_STYLES_URL", "https://map.threema.ch/styles/threema/style.json")
  109. stringBuildConfigField("MAP_POI_AROUND_URL", "https://poi.threema.ch/around/{latitude}/{longitude}/{radius}/")
  110. stringBuildConfigField("MAP_POI_NAMES_URL", "https://poi.threema.ch/names/{latitude}/{longitude}/{query}/")
  111. byteArrayBuildConfigField("THREEMA_PUSH_PUBLIC_KEY", PublicKeys.threemaPush)
  112. stringBuildConfigField("ONPREM_ID_PREFIX", "O")
  113. stringBuildConfigField("LOG_TAG", "3ma")
  114. stringBuildConfigField("DEFAULT_APP_THEME", "2")
  115. stringArrayBuildConfigField("ONPREM_CONFIG_TRUSTED_PUBLIC_KEYS", emptyArray())
  116. booleanBuildConfigField("MD_SYNC_DISTRIBUTION_LISTS", false)
  117. booleanBuildConfigField("AVAILABILITY_STATUS_ENABLED", false)
  118. booleanBuildConfigField("ERROR_REPORTING_SUPPORTED", false)
  119. // config fields for action URLs / deep links
  120. stringBuildConfigField("uriScheme", "threema")
  121. stringBuildConfigField("actionUrl", "go.threema.ch")
  122. stringBuildConfigField("contactActionUrl", "threema.id")
  123. // The OPPF url must be null in the default config. Do not change this.
  124. stringBuildConfigField("PRESET_OPPF_URL", null)
  125. setSentryConfig(
  126. projectId = 0,
  127. publicApikey = "",
  128. )
  129. with(manifestPlaceholders) {
  130. put("uriScheme", "threema")
  131. put("contactActionUrl", "threema.id")
  132. put("actionUrl", "go.threema.ch")
  133. put("callMimeType", "vnd.android.cursor.item/vnd.$applicationId.call")
  134. }
  135. testInstrumentationRunner = "$applicationId.ThreemaTestRunner"
  136. // Only include language resources for those languages
  137. androidResources.localeFilters.addAll(
  138. setOf(
  139. "en",
  140. "be-rBY",
  141. "bg",
  142. "ca",
  143. "cs",
  144. "de",
  145. "es",
  146. "fr",
  147. "gsw",
  148. "hu",
  149. "it",
  150. "ja",
  151. "nl-rNL",
  152. "no",
  153. "pl",
  154. "pt-rBR",
  155. "ru",
  156. "sk",
  157. "tr",
  158. "uk",
  159. "zh-rCN",
  160. "zh-rTW",
  161. ),
  162. )
  163. }
  164. splits {
  165. abi {
  166. isEnable = true
  167. reset()
  168. if (project.hasProperty("noAbiSplits")) {
  169. isUniversalApk = true
  170. } else {
  171. include("armeabi-v7a", "x86", "arm64-v8a", "x86_64")
  172. isUniversalApk = project.hasProperty("buildUniversalApk")
  173. }
  174. }
  175. }
  176. // Assign different version code for each output
  177. android.applicationVariants.all {
  178. outputs.all {
  179. if (this is ApkVariantOutputImpl) {
  180. val abi = getFilter("ABI")
  181. val abiVersionCode = when (abi) {
  182. "armeabi-v7a" -> 2
  183. "arm64-v8a" -> 3
  184. "x86" -> 8
  185. "x86_64" -> 9
  186. else -> 0
  187. }
  188. versionCodeOverride = abiVersionCode * 1_000_000 + defaultVersionCode
  189. }
  190. }
  191. }
  192. namespace = "ch.threema.app"
  193. flavorDimensions.add("default")
  194. productFlavors {
  195. create("none")
  196. create("store_google")
  197. create("store_threema") {
  198. stringResValue("shop_download_filename", "Threema-update.apk")
  199. }
  200. create("store_google_work") {
  201. versionName = "${appVersion}k$betaSuffix"
  202. applicationId = "ch.threema.app.work"
  203. testApplicationId = "$applicationId.test"
  204. setProductNames(appName = "Threema Work")
  205. stringResValue("package_name", applicationId!!)
  206. stringResValue("contacts_mime_type", "vnd.android.cursor.item/vnd.$applicationId.profile")
  207. stringResValue("call_mime_type", "vnd.android.cursor.item/vnd.$applicationId.call")
  208. stringBuildConfigField("CHAT_SERVER_PREFIX", "w-")
  209. stringBuildConfigField("CHAT_SERVER_IPV6_PREFIX", "ds.w-")
  210. stringBuildConfigField("MEDIA_PATH", "ThreemaWork")
  211. stringBuildConfigField("WORK_SERVER_URL_LEGACY", "https://apip-work.threema.ch/")
  212. stringBuildConfigField("WORK_SERVER_IPV6_URL_LEGACY", "https://ds-apip-work.threema.ch/")
  213. stringBuildConfigField("WORK_SERVER_URL", "https://work.threema.ch/")
  214. stringBuildConfigField("APP_RATING_URL", "https://threema.com/app-rating/android-work/{rating}")
  215. stringBuildConfigField("LOG_TAG", "3mawrk")
  216. stringBuildConfigField("DEFAULT_APP_THEME", "2")
  217. booleanBuildConfigField("AVAILABILITY_STATUS_ENABLED", true)
  218. // config fields for action URLs / deep links
  219. stringBuildConfigField("uriScheme", "threemawork")
  220. stringBuildConfigField("actionUrl", "work.threema.ch")
  221. stringBuildConfigField("SCREENSHOT_TEST_WORK_USERNAME", LocalProperties.getString("screenshotTestWorkUsername"))
  222. stringBuildConfigField("SCREENSHOT_TEST_WORK_PASSWORD", LocalProperties.getString("screenshotTestWorkPassword"))
  223. with(manifestPlaceholders) {
  224. put("uriScheme", "threemawork")
  225. put("actionUrl", "work.threema.ch")
  226. put("callMimeType", "vnd.android.cursor.item/vnd.$applicationId.call")
  227. }
  228. }
  229. create("green") {
  230. applicationId = "ch.threema.app.green"
  231. testApplicationId = "$applicationId.test"
  232. setProductNames(appName = "Threema Green")
  233. setSentryConfig(
  234. projectId = SentryConfig.SANDBOX_PROJECT_ID,
  235. publicApikey = SentryConfig.SANDBOX_PUBLIC_API_KEY,
  236. )
  237. stringResValue("package_name", applicationId!!)
  238. stringResValue("contacts_mime_type", "vnd.android.cursor.item/vnd.$applicationId.profile")
  239. stringResValue("call_mime_type", "vnd.android.cursor.item/vnd.$applicationId.call")
  240. stringBuildConfigField("MEDIA_PATH", "ThreemaGreen")
  241. stringBuildConfigField("CHAT_SERVER_SUFFIX", ".0.test.threema.ch")
  242. // This public key is pinned for the chat server protocol.
  243. byteArrayBuildConfigField("SERVER_PUBKEY", PublicKeys.sandboxServer)
  244. byteArrayBuildConfigField("SERVER_PUBKEY_ALT", PublicKeys.sandboxServer)
  245. stringBuildConfigField("DIRECTORY_SERVER_URL", "https://apip.test.threema.ch/")
  246. stringBuildConfigField("DIRECTORY_SERVER_IPV6_URL", "https://ds-apip.test.threema.ch/")
  247. stringBuildConfigField("MEDIATOR_SERVER_URL", "wss://mediator-{deviceGroupIdPrefix4}.test.threema.ch/{deviceGroupIdPrefix8}/")
  248. stringBuildConfigField("BLOB_SERVER_URL", "https://blobp-{blobIdPrefix}.test.threema.ch")
  249. stringBuildConfigField("BLOB_SERVER_IPV6_URL", "https://ds-blobp-{blobIdPrefix}.test.threema.ch")
  250. stringBuildConfigField("BLOB_SERVER_URL_UPLOAD", "https://blobp-upload.test.threema.ch/upload")
  251. stringBuildConfigField("BLOB_SERVER_IPV6_URL_UPLOAD", "https://ds-blobp-upload.test.threema.ch/upload")
  252. stringBuildConfigField("AVATAR_FETCH_URL", "https://avatar.test.threema.ch/")
  253. stringBuildConfigField("APP_RATING_URL", "https://test.threema.com/app-rating/android/{rating}")
  254. stringBuildConfigField("MAP_STYLES_URL", "https://map.test.threema.ch/styles/threema/style.json")
  255. stringBuildConfigField("MAP_POI_AROUND_URL", "https://poi.test.threema.ch/around/{latitude}/{longitude}/{radius}/")
  256. stringBuildConfigField("MAP_POI_NAMES_URL", "https://poi.test.threema.ch/names/{latitude}/{longitude}/{query}/")
  257. stringBuildConfigField("BLOB_MIRROR_SERVER_URL", "https://blob-mirror-{deviceGroupIdPrefix4}.test.threema.ch/{deviceGroupIdPrefix8}")
  258. booleanBuildConfigField("ERROR_REPORTING_SUPPORTED", true)
  259. }
  260. create("sandbox_work") {
  261. versionName = "${appVersion}k$betaSuffix"
  262. applicationId = "ch.threema.app.sandbox.work"
  263. testApplicationId = "$applicationId.test"
  264. setProductNames(
  265. appName = "Threema Sandbox Work",
  266. appNameDesktop = "Threema Blue",
  267. )
  268. setSentryConfig(
  269. projectId = SentryConfig.SANDBOX_PROJECT_ID,
  270. publicApikey = SentryConfig.SANDBOX_PUBLIC_API_KEY,
  271. )
  272. stringResValue("package_name", applicationId!!)
  273. stringResValue("contacts_mime_type", "vnd.android.cursor.item/vnd.$applicationId.profile")
  274. stringResValue("call_mime_type", "vnd.android.cursor.item/vnd.$applicationId.call")
  275. stringBuildConfigField("CHAT_SERVER_PREFIX", "w-")
  276. stringBuildConfigField("CHAT_SERVER_IPV6_PREFIX", "ds.w-")
  277. stringBuildConfigField("CHAT_SERVER_SUFFIX", ".0.test.threema.ch")
  278. stringBuildConfigField("MEDIA_PATH", "ThreemaWorkSandbox")
  279. // This public key is pinned for the chat server protocol.
  280. byteArrayBuildConfigField("SERVER_PUBKEY", PublicKeys.sandboxServer)
  281. byteArrayBuildConfigField("SERVER_PUBKEY_ALT", PublicKeys.sandboxServer)
  282. stringBuildConfigField("DIRECTORY_SERVER_URL", "https://apip.test.threema.ch/")
  283. stringBuildConfigField("DIRECTORY_SERVER_IPV6_URL", "https://ds-apip.test.threema.ch/")
  284. stringBuildConfigField("WORK_SERVER_URL_LEGACY", "https://apip-work.test.threema.ch/")
  285. stringBuildConfigField("WORK_SERVER_IPV6_URL_LEGACY", "https://ds-apip-work.test.threema.ch/")
  286. stringBuildConfigField("WORK_SERVER_URL", "https://work.test.threema.ch/")
  287. stringBuildConfigField("MEDIATOR_SERVER_URL", "wss://mediator-{deviceGroupIdPrefix4}.test.threema.ch/{deviceGroupIdPrefix8}/")
  288. stringBuildConfigField("BLOB_SERVER_URL", "https://blobp-{blobIdPrefix}.test.threema.ch")
  289. stringBuildConfigField("BLOB_SERVER_IPV6_URL", "https://ds-blobp-{blobIdPrefix}.test.threema.ch")
  290. stringBuildConfigField("BLOB_SERVER_URL_UPLOAD", "https://blobp-upload.test.threema.ch/upload")
  291. stringBuildConfigField("BLOB_SERVER_IPV6_URL_UPLOAD", "https://ds-blobp-upload.test.threema.ch/upload")
  292. stringBuildConfigField("AVATAR_FETCH_URL", "https://avatar.test.threema.ch/")
  293. stringBuildConfigField("APP_RATING_URL", "https://test.threema.com/app-rating/android-work/{rating}")
  294. stringBuildConfigField("MAP_STYLES_URL", "https://map.test.threema.ch/styles/threema/style.json")
  295. stringBuildConfigField("MAP_POI_AROUND_URL", "https://poi.test.threema.ch/around/{latitude}/{longitude}/{radius}/")
  296. stringBuildConfigField("MAP_POI_NAMES_URL", "https://poi.test.threema.ch/names/{latitude}/{longitude}/{query}/")
  297. stringBuildConfigField("LOG_TAG", "3mawrk")
  298. stringBuildConfigField("DEFAULT_APP_THEME", "2")
  299. stringBuildConfigField("BLOB_MIRROR_SERVER_URL", "https://blob-mirror-{deviceGroupIdPrefix4}.test.threema.ch/{deviceGroupIdPrefix8}")
  300. // config fields for action URLs / deep links
  301. stringBuildConfigField("uriScheme", "threemawork")
  302. stringBuildConfigField("actionUrl", "work.test.threema.ch")
  303. booleanBuildConfigField("AVAILABILITY_STATUS_ENABLED", true)
  304. booleanBuildConfigField("ERROR_REPORTING_SUPPORTED", true)
  305. stringBuildConfigField("MD_CLIENT_DOWNLOAD_URL", "https://three.ma/mdw")
  306. with(manifestPlaceholders) {
  307. put("uriScheme", "threemawork")
  308. put("actionUrl", "work.test.threema.ch")
  309. }
  310. }
  311. create("onprem") {
  312. versionName = "${appVersion}o$betaSuffix"
  313. applicationId = "ch.threema.app.onprem"
  314. testApplicationId = "$applicationId.test"
  315. setProductNames(
  316. appName = "Threema OnPrem",
  317. shortAppName = "Threema",
  318. companyName = "Threema",
  319. )
  320. stringResValue("package_name", applicationId!!)
  321. stringResValue("contacts_mime_type", "vnd.android.cursor.item/vnd.$applicationId.profile")
  322. stringResValue("call_mime_type", "vnd.android.cursor.item/vnd.$applicationId.call")
  323. intBuildConfigField("MAX_GROUP_SIZE", 256)
  324. stringBuildConfigField("CHAT_SERVER_PREFIX", "")
  325. stringBuildConfigField("CHAT_SERVER_IPV6_PREFIX", "")
  326. stringBuildConfigField("CHAT_SERVER_SUFFIX", null)
  327. stringBuildConfigField("MEDIA_PATH", "ThreemaOnPrem")
  328. booleanBuildConfigField("CHAT_SERVER_GROUPS", false)
  329. byteArrayBuildConfigField("SERVER_PUBKEY", null)
  330. byteArrayBuildConfigField("SERVER_PUBKEY_ALT", null)
  331. stringBuildConfigField("DIRECTORY_SERVER_URL", null)
  332. stringBuildConfigField("DIRECTORY_SERVER_IPV6_URL", null)
  333. stringBuildConfigField("BLOB_SERVER_URL", null)
  334. stringBuildConfigField("BLOB_SERVER_IPV6_URL", null)
  335. stringBuildConfigField("BLOB_SERVER_URL_UPLOAD", null)
  336. stringBuildConfigField("BLOB_SERVER_IPV6_URL_UPLOAD", null)
  337. stringBuildConfigField("BLOB_MIRROR_SERVER_URL", null)
  338. stringArrayBuildConfigField("ONPREM_CONFIG_TRUSTED_PUBLIC_KEYS", PublicKeys.onPremTrusted)
  339. stringBuildConfigField("LOG_TAG", "3maop")
  340. // config fields for action URLs / deep links
  341. val uriScheme = "threemaonprem"
  342. val actionUrl = "onprem.threema.ch"
  343. stringBuildConfigField("uriScheme", uriScheme)
  344. stringBuildConfigField("actionUrl", actionUrl)
  345. stringBuildConfigField("PRESET_OPPF_URL", null)
  346. stringBuildConfigField("MD_CLIENT_DOWNLOAD_URL", "https://three.ma/mdo")
  347. stringBuildConfigField("SCREENSHOT_TEST_ONPREM_USERNAME", LocalProperties.getString("screenshotTestOnPremUsername"))
  348. stringBuildConfigField("SCREENSHOT_TEST_ONPREM_PASSWORD", LocalProperties.getString("screenshotTestOnPremPassword"))
  349. stringBuildConfigField("SCREENSHOT_TEST_ONPREM_SERVER_URL", LocalProperties.getString("screenshotTestOnPremServerUrl"))
  350. with(manifestPlaceholders) {
  351. put("uriScheme", uriScheme)
  352. put("actionUrl", actionUrl)
  353. put("callMimeType", "vnd.android.cursor.item/vnd.$applicationId.call")
  354. }
  355. }
  356. create("blue") {
  357. // Essentially like sandbox work, but with a different icon and application id, used for internal testing
  358. versionName = "${appVersion}b$betaSuffix"
  359. // The app was previously named `red`. The app id remains unchanged to still be able to install updates.
  360. applicationId = "ch.threema.app.red"
  361. testApplicationId = "ch.threema.app.blue.test"
  362. setProductNames(appName = "Threema Blue")
  363. setSentryConfig(
  364. projectId = SentryConfig.SANDBOX_PROJECT_ID,
  365. publicApikey = SentryConfig.SANDBOX_PUBLIC_API_KEY,
  366. )
  367. stringResValue("package_name", applicationId!!)
  368. stringResValue("contacts_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.blue.profile")
  369. stringResValue("call_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.blue.call")
  370. stringBuildConfigField("CHAT_SERVER_PREFIX", "w-")
  371. stringBuildConfigField("CHAT_SERVER_IPV6_PREFIX", "ds.w-")
  372. stringBuildConfigField("CHAT_SERVER_SUFFIX", ".0.test.threema.ch")
  373. stringBuildConfigField("MEDIA_PATH", "ThreemaBlue")
  374. // This public key is pinned for the chat server protocol.
  375. byteArrayBuildConfigField("SERVER_PUBKEY", PublicKeys.sandboxServer)
  376. byteArrayBuildConfigField("SERVER_PUBKEY_ALT", PublicKeys.sandboxServer)
  377. stringBuildConfigField("DIRECTORY_SERVER_URL", "https://apip.test.threema.ch/")
  378. stringBuildConfigField("DIRECTORY_SERVER_IPV6_URL", "https://ds-apip.test.threema.ch/")
  379. stringBuildConfigField("WORK_SERVER_URL_LEGACY", "https://apip-work.test.threema.ch/")
  380. stringBuildConfigField("WORK_SERVER_IPV6_URL_LEGACY", "https://ds-apip-work.test.threema.ch/")
  381. stringBuildConfigField("WORK_SERVER_URL", "https://work.test.threema.ch/")
  382. stringBuildConfigField("MEDIATOR_SERVER_URL", "wss://mediator-{deviceGroupIdPrefix4}.test.threema.ch/{deviceGroupIdPrefix8}/")
  383. stringBuildConfigField("BLOB_SERVER_URL", "https://blobp-{blobIdPrefix}.test.threema.ch")
  384. stringBuildConfigField("BLOB_SERVER_IPV6_URL", "https://ds-blobp-{blobIdPrefix}.test.threema.ch")
  385. stringBuildConfigField("BLOB_SERVER_URL_UPLOAD", "https://blobp-upload.test.threema.ch/upload")
  386. stringBuildConfigField("BLOB_SERVER_IPV6_URL_UPLOAD", "https://ds-blobp-upload.test.threema.ch/upload")
  387. stringBuildConfigField("AVATAR_FETCH_URL", "https://avatar.test.threema.ch/")
  388. stringBuildConfigField("APP_RATING_URL", "https://test.threema.com/app-rating/android-work/{rating}")
  389. stringBuildConfigField("MAP_STYLES_URL", "https://map.test.threema.ch/styles/threema/style.json")
  390. stringBuildConfigField("MAP_POI_AROUND_URL", "https://poi.test.threema.ch/around/{latitude}/{longitude}/{radius}/")
  391. stringBuildConfigField("MAP_POI_NAMES_URL", "https://poi.test.threema.ch/names/{latitude}/{longitude}/{query}/")
  392. stringBuildConfigField("LOG_TAG", "3mablue")
  393. stringBuildConfigField("BLOB_MIRROR_SERVER_URL", "https://blob-mirror-{deviceGroupIdPrefix4}.test.threema.ch/{deviceGroupIdPrefix8}")
  394. booleanBuildConfigField("AVAILABILITY_STATUS_ENABLED", true)
  395. booleanBuildConfigField("ERROR_REPORTING_SUPPORTED", true)
  396. // config fields for action URLs / deep links
  397. stringBuildConfigField("uriScheme", "threemablue")
  398. stringBuildConfigField("actionUrl", "blue.threema.ch")
  399. with(manifestPlaceholders) {
  400. put("uriScheme", "threemablue")
  401. put("actionUrl", "blue.threema.ch")
  402. put("callMimeType", "vnd.android.cursor.item/vnd.ch.threema.app.blue.call")
  403. }
  404. }
  405. create("hms") {
  406. applicationId = "ch.threema.app.hms"
  407. }
  408. create("hms_work") {
  409. versionName = "${appVersion}k$betaSuffix"
  410. applicationId = "ch.threema.app.work.hms"
  411. testApplicationId = "ch.threema.app.work.test.hms"
  412. setProductNames(appName = "Threema Work")
  413. stringResValue("package_name", "ch.threema.app.work")
  414. stringResValue("contacts_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.work.profile")
  415. stringResValue("call_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.work.call")
  416. stringBuildConfigField("CHAT_SERVER_PREFIX", "w-")
  417. stringBuildConfigField("CHAT_SERVER_IPV6_PREFIX", "ds.w-")
  418. stringBuildConfigField("MEDIA_PATH", "ThreemaWork")
  419. stringBuildConfigField("WORK_SERVER_URL_LEGACY", "https://apip-work.threema.ch/")
  420. stringBuildConfigField("WORK_SERVER_IPV6_URL_LEGACY", "https://ds-apip-work.threema.ch/")
  421. stringBuildConfigField("WORK_SERVER_URL", "https://work.threema.ch/")
  422. stringBuildConfigField("APP_RATING_URL", "https://threema.com/app-rating/android-work/{rating}")
  423. stringBuildConfigField("LOG_TAG", "3mawrk")
  424. stringBuildConfigField("DEFAULT_APP_THEME", "2")
  425. booleanBuildConfigField("AVAILABILITY_STATUS_ENABLED", true)
  426. // config fields for action URLs / deep links
  427. stringBuildConfigField("uriScheme", "threemawork")
  428. stringBuildConfigField("actionUrl", "work.threema.ch")
  429. with(manifestPlaceholders) {
  430. put("uriScheme", "threemawork")
  431. put("actionUrl", "work.threema.ch")
  432. put("callMimeType", "vnd.android.cursor.item/vnd.ch.threema.app.work.call")
  433. }
  434. }
  435. create("libre") {
  436. versionName = "${appVersion}l$betaSuffix"
  437. applicationId = "ch.threema.app.libre"
  438. testApplicationId = "$applicationId.test"
  439. stringResValue("package_name", applicationId!!)
  440. setProductNames(
  441. appName = "Threema Libre",
  442. appNameDesktop = "Threema",
  443. )
  444. stringBuildConfigField("MEDIA_PATH", "ThreemaLibre")
  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. implementation(libs.sqlcipher.android)
  753. implementation(libs.subsamplingScaleImageView)
  754. implementation(libs.opencsv)
  755. implementation(libs.zip4j)
  756. implementation(libs.taptargetview)
  757. implementation(libs.slf4j.api)
  758. implementation(libs.androidImageCropper)
  759. implementation(libs.fastscroll)
  760. implementation(libs.ezVcard)
  761. implementation(libs.gestureViews)
  762. // AndroidX / Jetpack support libraries
  763. implementation(libs.androidx.preference)
  764. implementation(libs.androidx.recyclerview)
  765. implementation(libs.androidx.palette)
  766. implementation(libs.androidx.swiperefreshlayout)
  767. implementation(libs.androidx.core)
  768. implementation(libs.androidx.appcompat)
  769. implementation(libs.androidx.constraintlayout)
  770. implementation(libs.androidx.biometric)
  771. implementation(libs.androidx.work.runtime)
  772. implementation(libs.androidx.fragment)
  773. implementation(libs.androidx.activity)
  774. implementation(libs.androidx.sqlite)
  775. implementation(libs.androidx.concurrent.futures)
  776. implementation(libs.androidx.camera2)
  777. implementation(libs.androidx.camera.lifecycle)
  778. implementation(libs.androidx.camera.view)
  779. implementation(libs.androidx.camera.video)
  780. implementation(libs.androidx.media)
  781. implementation(libs.androidx.media3.exoplayer)
  782. implementation(libs.androidx.media3.ui)
  783. implementation(libs.androidx.media3.session)
  784. implementation(libs.androidx.lifecycle.viewmodel)
  785. implementation(libs.androidx.lifecycle.livedata)
  786. implementation(libs.androidx.lifecycle.runtime)
  787. implementation(libs.androidx.lifecycle.viewmodel.savedstate)
  788. implementation(libs.androidx.lifecycle.service)
  789. implementation(libs.androidx.lifecycle.process)
  790. implementation(libs.androidx.lifecycle.commonJava8)
  791. implementation(libs.androidx.lifecycle.extensions)
  792. implementation(libs.androidx.paging.runtime)
  793. implementation(libs.androidx.sharetarget)
  794. implementation(libs.androidx.room.runtime)
  795. implementation(libs.androidx.window)
  796. implementation(libs.androidx.splashscreen)
  797. ksp(libs.androidx.room.compiler)
  798. // Jetpack Compose
  799. implementation(platform(libs.compose.bom))
  800. implementation(libs.androidx.material3)
  801. implementation(libs.androidx.ui.tooling.preview)
  802. implementation(libs.androidx.activity.compose)
  803. implementation(libs.androidx.lifecycle.viewmodel.compose)
  804. implementation(libs.androidx.lifecycle.runtime.compose)
  805. debugImplementation(libs.androidx.ui.tooling)
  806. debugImplementation(libs.androidx.ui.test.manifest)
  807. androidTestImplementation(platform(libs.compose.bom))
  808. implementation(libs.bcprov.jdk15to18)
  809. implementation(libs.material)
  810. implementation(libs.zxing)
  811. implementation(libs.libphonenumber)
  812. // webclient dependencies
  813. implementation(libs.msgpack.core)
  814. implementation(libs.jackson.core)
  815. implementation(libs.nvWebsocket.client)
  816. implementation(libs.saltyrtc.client) {
  817. exclude(group = "org.json")
  818. }
  819. implementation(libs.chunkedDc)
  820. implementation(libs.webrtcAndroid)
  821. implementation(libs.saltyrtc.taskWebrtc) {
  822. exclude(module = "saltyrtc-client")
  823. }
  824. // Glide components
  825. implementation(libs.glide)
  826. ksp(libs.glide.ksp)
  827. // Kotlin
  828. implementation(libs.kotlin.stdlib)
  829. implementation(libs.kotlinx.coroutines.android)
  830. implementation(libs.kotlinx.serialization.json)
  831. testImplementation(libs.kotlin.test)
  832. androidTestImplementation(libs.kotlin.test)
  833. // use leak canary in debug builds if requested
  834. if (project.hasProperty("leakCanary")) {
  835. debugImplementation(libs.leakcanary)
  836. }
  837. // test dependencies
  838. testImplementation(libs.junit)
  839. testImplementation(testFixtures(project(":domain")))
  840. // custom test helpers, shared between unit test and android tests
  841. testImplementation(project(":test-helpers"))
  842. androidTestImplementation(project(":test-helpers"))
  843. testImplementation(libs.mockk)
  844. androidTestImplementation(libs.mockkAndroid)
  845. // add JSON support to tests without mocking
  846. testImplementation(libs.json)
  847. testImplementation(libs.archunit.junit4)
  848. androidTestImplementation(testFixtures(project(":domain")))
  849. androidTestImplementation(libs.androidx.test.rules)
  850. androidTestImplementation(libs.fastlane.screengrab) {
  851. exclude(group = "androidx.annotation", module = "annotation")
  852. }
  853. androidTestImplementation(libs.androidx.espresso.core) {
  854. exclude(group = "androidx.annotation", module = "annotation")
  855. }
  856. androidTestImplementation(libs.androidx.test.runner) {
  857. exclude(group = "androidx.annotation", module = "annotation")
  858. }
  859. androidTestImplementation(libs.androidx.junit)
  860. androidTestImplementation(libs.androidx.espresso.contrib) {
  861. exclude(group = "androidx.annotation", module = "annotation")
  862. exclude(group = "androidx.appcompat", module = "appcompat")
  863. exclude(group = "androidx.legacy", module = "legacy-support-v4")
  864. exclude(group = "com.google.android.material", module = "material")
  865. exclude(group = "androidx.recyclerview", module = "recyclerview")
  866. exclude(group = "org.checkerframework", module = "checker")
  867. exclude(module = "protobuf-lite")
  868. }
  869. androidTestImplementation(libs.androidx.espresso.intents) {
  870. exclude(group = "androidx.annotation", module = "annotation")
  871. }
  872. androidTestImplementation(libs.androidx.test.uiautomator)
  873. androidTestImplementation(libs.androidx.test.core)
  874. androidTestImplementation(libs.kotlinx.coroutines.test)
  875. androidTestImplementation(libs.androidx.ui.test.junit4)
  876. testImplementation(libs.kotlinx.coroutines.test)
  877. // Google Play Services and related libraries
  878. "noneImplementation"(libs.playServices.base)
  879. "store_googleImplementation"(libs.playServices.base)
  880. "store_google_workImplementation"(libs.playServices.base)
  881. "store_threemaImplementation"(libs.playServices.base)
  882. "onpremImplementation"(libs.playServices.base)
  883. "greenImplementation"(libs.playServices.base)
  884. "sandbox_workImplementation"(libs.playServices.base)
  885. "blueImplementation"(libs.playServices.base)
  886. fun ExternalModuleDependency.excludeFirebaseDependencies() {
  887. exclude(group = "com.google.firebase", module = "firebase-core")
  888. exclude(group = "com.google.firebase", module = "firebase-analytics")
  889. exclude(group = "com.google.firebase", module = "firebase-measurement-connector")
  890. }
  891. "noneImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  892. "store_googleImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  893. "store_google_workImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  894. "store_threemaImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  895. "onpremImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  896. "greenImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  897. "sandbox_workImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  898. "blueImplementation"(libs.firebase.messaging) { excludeFirebaseDependencies() }
  899. // Google Assistant Voice Action verification library
  900. "noneImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  901. "store_googleImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  902. "store_google_workImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  903. "onpremImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  904. "store_threemaImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  905. "greenImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  906. "sandbox_workImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  907. "blueImplementation"(group = "", name = "libgsaverification-client", ext = "aar")
  908. // Maplibre (may have transitive dependencies on Google location services)
  909. "noneImplementation"(libs.maplibre)
  910. "store_googleImplementation"(libs.maplibre)
  911. "store_google_workImplementation"(libs.maplibre)
  912. "store_threemaImplementation"(libs.maplibre)
  913. "libreImplementation"(libs.maplibre) {
  914. exclude(group = "com.google.android.gms")
  915. }
  916. "onpremImplementation"(libs.maplibre)
  917. "greenImplementation"(libs.maplibre)
  918. "sandbox_workImplementation"(libs.maplibre)
  919. "blueImplementation"(libs.maplibre)
  920. "hmsImplementation"(libs.maplibre)
  921. "hms_workImplementation"(libs.maplibre)
  922. // Huawei related libraries (only for hms* build variants)
  923. // Exclude agconnect dependency, we'll replace it with the vendored version below
  924. "hmsImplementation"(libs.hmsPush) {
  925. exclude(group = "com.huawei.agconnect")
  926. }
  927. "hms_workImplementation"(libs.hmsPush) {
  928. exclude(group = "com.huawei.agconnect")
  929. }
  930. "hmsImplementation"(group = "", name = "agconnect-core-1.9.1.301", ext = "aar")
  931. "hms_workImplementation"(group = "", name = "agconnect-core-1.9.1.301", ext = "aar")
  932. }
  933. // Define the cargo attributes. These will be used by the rust-android plugin that will create the
  934. // 'cargoBuild' task that builds native libraries that will be added to the apk. Note that the
  935. // kotlin bindings are created in the domain module. Building native libraries with rust-android
  936. // cannot be done in any other module than 'app'.
  937. cargo {
  938. prebuiltToolchains = true
  939. targetDirectory = "$projectDir/build/generated/source/libthreema"
  940. module = "$projectDir/../domain/libthreema" // must contain Cargo.toml
  941. libname = "libthreema" // must match the Cargo.toml's package name
  942. profile = "release"
  943. pythonCommand = "python3"
  944. targets = listOf("x86_64", "arm64", "arm", "x86")
  945. features {
  946. defaultAnd(arrayOf("uniffi"))
  947. }
  948. extraCargoBuildArguments = listOf("--lib", "--target-dir", "$projectDir/build/generated/source/libthreema", "--locked")
  949. verbose = false
  950. }
  951. afterEvaluate {
  952. // The `cargoBuild` task isn't available until after evaluation.
  953. android.applicationVariants.configureEach {
  954. val variantName = name.replaceFirstChar { it.uppercase() }
  955. // Set the dependency so that cargoBuild is executed before the native libs are merged
  956. tasks["merge${variantName}NativeLibs"].dependsOn(tasks["cargoBuild"])
  957. }
  958. }
  959. sonarqube {
  960. properties {
  961. property(
  962. "sonar.sources",
  963. listOf(
  964. "src/main/",
  965. "../scripts/",
  966. "../scripts-internal/",
  967. )
  968. .joinToString(separator = ", "),
  969. )
  970. property(
  971. "sonar.exclusions",
  972. listOf(
  973. "src/**/res/",
  974. "src/**/res-rendezvous/",
  975. "**/emojis/EmojiParser.kt",
  976. "**/emojis/EmojiSpritemap.kt",
  977. )
  978. .joinToString(separator = ", "),
  979. )
  980. property("sonar.tests", "src/test/")
  981. property("sonar.sourceEncoding", "UTF-8")
  982. property("sonar.verbose", "true")
  983. property("sonar.projectKey", "android-client")
  984. property("sonar.projectName", "Threema for Android")
  985. }
  986. }
  987. androidStem {
  988. includeLocalizedOnlyTemplates = true
  989. }
  990. tasks.register<Exec>("compileProto") {
  991. group = "build"
  992. description = "generate class bindings from protobuf files in the 'protobuf' directory"
  993. workingDir(project.projectDir)
  994. commandLine("./compile-proto.sh")
  995. }
  996. project.tasks.preBuild.dependsOn("compileProto")
  997. tasks.withType<Test> {
  998. // Necessary to load the dynamic libthreema library in unit tests
  999. systemProperty("jna.library.path", "${project.projectDir}/../domain/libthreema/target/release")
  1000. }
  1001. // Set up Gradle tasks to fetch screenshots on UI test failures
  1002. // See https://medium.com/stepstone-tech/how-to-capture-screenshots-for-failed-ui-tests-9927eea6e1e4
  1003. val reportsDirectory = "${layout.buildDirectory}/reports/androidTests/connected"
  1004. val screenshotsDirectory = "/sdcard/testfailures/screenshots/"
  1005. val clearScreenshotsTask = tasks.register<Exec>("clearScreenshots") {
  1006. executable = android.adbExecutable.toString()
  1007. args("shell", "rm", "-r", screenshotsDirectory)
  1008. }
  1009. val createScreenshotsDirectoryTask = tasks.register<Exec>("createScreenshotsDirectory") {
  1010. group = "reporting"
  1011. executable = android.adbExecutable.toString()
  1012. args("shell", "mkdir", "-p", screenshotsDirectory)
  1013. }
  1014. val fetchScreenshotsTask = tasks.register<Exec>("fetchScreenshots") {
  1015. group = "reporting"
  1016. executable = android.adbExecutable.toString()
  1017. args("pull", "$screenshotsDirectory.", reportsDirectory)
  1018. finalizedBy(clearScreenshotsTask)
  1019. dependsOn(createScreenshotsDirectoryTask)
  1020. doFirst {
  1021. file(reportsDirectory).mkdirs()
  1022. }
  1023. }
  1024. tasks.whenTaskAdded {
  1025. if (name == "connectedDebugAndroidTest") {
  1026. finalizedBy(fetchScreenshotsTask)
  1027. }
  1028. }
  1029. // Let the compose compiler generate stability reports
  1030. tasks.withType<KotlinCompile>().configureEach {
  1031. compilerOptions {
  1032. val composeCompilerReportsPath = "${project.layout.buildDirectory.get().dir("compose_compiler").asFile.absolutePath}/reports"
  1033. freeCompilerArgs.addAll(
  1034. listOf(
  1035. "-P",
  1036. "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=$composeCompilerReportsPath",
  1037. ),
  1038. )
  1039. }
  1040. }