build.gradle 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. plugins {
  2. id 'org.sonarqube'
  3. }
  4. apply plugin: 'com.android.application'
  5. apply plugin: 'kotlin-android'
  6. // rules to allow test running with a real android jar implementation of URI, Uri.Builder for group link encoding
  7. apply plugin: 'de.mobilej.unmock'
  8. unMock {
  9. keepStartingWith "android.net.Uri"
  10. keep "android.net.Uri"
  11. keepAndRename "java.nio.charset.Charsets" to "xjava.nio.charset.Charsets"
  12. keepStartingWith "libcore."
  13. }
  14. // only apply the plugin if we are dealing with a AppGallery build
  15. if (getGradle().getStartParameter().getTaskRequests().toString().contains("Hms")) {
  16. println "enabling hms plugin"
  17. apply plugin: 'com.huawei.agconnect'
  18. }
  19. // version codes
  20. def app_version = "4.6"
  21. def beta_suffix = "" // with leading dash
  22. /**
  23. * Return the git hash, if git is installed.
  24. */
  25. def getGitHash = { ->
  26. def stdout = new ByteArrayOutputStream()
  27. def stderr = new ByteArrayOutputStream()
  28. try {
  29. exec {
  30. commandLine 'git', 'rev-parse', '--short', 'HEAD'
  31. standardOutput = stdout
  32. errorOutput = stderr
  33. ignoreExitValue true
  34. }
  35. } catch (ignored) { /* If git binary is not found, carry on */ }
  36. def hash = stdout.toString().trim()
  37. return (hash.isEmpty()) ? "?" : hash
  38. }
  39. /**
  40. * Look up the keystore with the specified name in a `keystore` directory
  41. * adjacent to this project directory. If it exists, return a signing config.
  42. * Otherwise, return null.
  43. */
  44. def findKeystore = { name ->
  45. def basePath = "${projectDir.getAbsolutePath()}/../../keystore"
  46. def storePath = "${basePath}/${name}.keystore"
  47. def storeFile = new File(storePath)
  48. if (storeFile.exists() && storeFile.isFile()) {
  49. def propertiesPath = "${basePath}/${name}.properties"
  50. def propertiesFile = new File(propertiesPath)
  51. if (propertiesFile.exists() && propertiesFile.isFile()) {
  52. Properties props = new Properties()
  53. propertiesFile.withInputStream { props.load(it) }
  54. return [
  55. storeFile: storePath,
  56. storePassword: props.storePassword,
  57. keyAlias: props.keyAlias,
  58. keyPassword: props.keyPassword,
  59. ]
  60. } else {
  61. return [
  62. storeFile: storePath,
  63. storePassword: null,
  64. keyAlias: null,
  65. keyPassword: null,
  66. ]
  67. }
  68. }
  69. }
  70. /**
  71. * Map with keystore paths (if found).
  72. */
  73. def keystores = [
  74. debug: findKeystore("debug"),
  75. release: findKeystore("threema"),
  76. hms_release: findKeystore("threema_hms"),
  77. onprem_release: findKeystore("onprem"),
  78. red_release: findKeystore("red"),
  79. ]
  80. android {
  81. // NOTE: When adjusting compileSdkVersion, buildToolsVersion or ndkVersion,
  82. // make sure to adjust them in `scripts/Dockerfile` and
  83. // `.gitlab-ci.yml` as well!
  84. compileSdkVersion 30
  85. buildToolsVersion '30.0.3'
  86. ndkVersion '21.1.6352462'
  87. defaultConfig {
  88. minSdkVersion 21
  89. //noinspection OldTargetApi
  90. targetSdkVersion 30
  91. vectorDrawables.useSupportLibrary = true
  92. applicationId "ch.threema.app"
  93. testApplicationId 'ch.threema.app.test'
  94. versionCode 705
  95. versionName "${app_version}${beta_suffix}"
  96. resValue "string", "app_name", "Threema"
  97. // package name used for sync adapter
  98. resValue "string", "package_name", applicationId
  99. resValue "string", "contacts_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.profile"
  100. resValue "string", "call_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.call"
  101. buildConfigField "int", "MAX_GROUP_SIZE", "256"
  102. buildConfigField "String", "CHAT_SERVER_PREFIX", "\"g-\""
  103. buildConfigField "String", "CHAT_SERVER_IPV6_PREFIX", "\"ds.g-\""
  104. buildConfigField "String", "CHAT_SERVER_SUFFIX", "\".0.threema.ch\""
  105. buildConfigField "int[]", "CHAT_SERVER_PORTS", "{5222, 443}"
  106. buildConfigField "String", "MEDIA_PATH", "\"Threema\""
  107. buildConfigField "boolean", "CHAT_SERVER_GROUPS", "true"
  108. buildConfigField "boolean", "DISABLE_CERT_PINNING", "false"
  109. buildConfigField "boolean", "VIDEO_CALLS_ENABLED", "true"
  110. buildConfigField "byte[]", "SERVER_PUBKEY", "new byte[] {(byte) 0x45, (byte) 0x0b, (byte) 0x97, (byte) 0x57, (byte) 0x35, (byte) 0x27, (byte) 0x9f, (byte) 0xde, (byte) 0xcb, (byte) 0x33, (byte) 0x13, (byte) 0x64, (byte) 0x8f, (byte) 0x5f, (byte) 0xc6, (byte) 0xee, (byte) 0x9f, (byte) 0xf4, (byte) 0x36, (byte) 0x0e, (byte) 0xa9, (byte) 0x2a, (byte) 0x8c, (byte) 0x17, (byte) 0x51, (byte) 0xc6, (byte) 0x61, (byte) 0xe4, (byte) 0xc0, (byte) 0xd8, (byte) 0xc9, (byte) 0x09 }"
  111. buildConfigField "byte[]", "SERVER_PUBKEY_ALT", "new byte[] {(byte) 0xda, (byte) 0x7c, (byte) 0x73, (byte) 0x79, (byte) 0x8f, (byte) 0x97, (byte) 0xd5, (byte) 0x87, (byte) 0xc3, (byte) 0xa2, (byte) 0x5e, (byte) 0xbe, (byte) 0x0a, (byte) 0x91, (byte) 0x41, (byte) 0x7f, (byte) 0x76, (byte) 0xdb, (byte) 0xcc, (byte) 0xcd, (byte) 0xda, (byte) 0x29, (byte) 0x30, (byte) 0xe6, (byte) 0xa9, (byte) 0x09, (byte) 0x0a, (byte) 0xf6, (byte) 0x2e, (byte) 0xba, (byte) 0x6f, (byte) 0x15 }"
  112. buildConfigField "String", "GIT_HASH", "\"${getGitHash()}\""
  113. buildConfigField "String", "DIRECTORY_SERVER_URL", "\"https://apip.threema.ch/\""
  114. buildConfigField "String", "DIRECTORY_SERVER_IPV6_URL", "\"https://ds-apip.threema.ch/\""
  115. buildConfigField "String", "WORK_SERVER_URL", "null"
  116. buildConfigField "String", "WORK_SERVER_IPV6_URL", "null"
  117. buildConfigField "String", "BLOB_SERVER_DOWNLOAD_URL", "\"https://blobp-{blobIdPrefix}.threema.ch/{blobId}\""
  118. buildConfigField "String", "BLOB_SERVER_DOWNLOAD_IPV6_URL", "\"https://ds-blobp-{blobIdPrefix}.threema.ch/{blobId}\""
  119. buildConfigField "String", "BLOB_SERVER_DONE_URL", "\"https://blobp-{blobIdPrefix}.threema.ch/{blobId}/done\""
  120. buildConfigField "String", "BLOB_SERVER_DONE_IPV6_URL", "\"https://ds-blobp-{blobIdPrefix}.threema.ch/{blobId}/done\""
  121. buildConfigField "String", "BLOB_SERVER_UPLOAD_URL", "\"https://blobp-upload.threema.ch/upload\""
  122. buildConfigField "String", "BLOB_SERVER_UPLOAD_IPV6_URL", "\"https://ds-blobp-upload.threema.ch/upload\""
  123. buildConfigField "String", "AVATAR_FETCH_URL", "\"https://avatar.threema.ch/\""
  124. buildConfigField "String", "SAFE_SERVER_URL", "\"https://safe-%h.threema.ch/\""
  125. buildConfigField "String", "ONPREM_ID_PREFIX", "\"O\""
  126. buildConfigField "String[]", "ONPREM_CONFIG_TRUSTED_PUBLIC_KEYS", "null"
  127. buildConfigField "boolean", "SEND_CONSUMED_DELIVERY_RECEIPTS", "false"
  128. // config fields for action URLs / deep links
  129. buildConfigField "String", "uriScheme", "\"threema\""
  130. buildConfigField "String", "actionUrl", "\"go.threema.ch\""
  131. buildConfigField "String", "contactActionUrl", "\"threema.id\""
  132. buildConfigField "String", "groupLinkActionUrl", "\"threema.group\""
  133. // duplicated for manifest
  134. manifestPlaceholders = [
  135. uriScheme: "threema",
  136. contactActionUrl: "threema.id",
  137. groupLinkActionUrl: "threema.group",
  138. actionUrl: "go.threema.ch"
  139. ]
  140. ndk {
  141. abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
  142. }
  143. testInstrumentationRunner 'ch.threema.app.ThreemaTestRunner'
  144. testInstrumentationRunnerArgument 'notAnnotation', 'ch.threema.app.TestFastlaneOnly,ch.threema.app.DangerousTest'
  145. testInstrumentationRunnerArgument 'disableAnalytics', 'true' // https://developer.android.com/training/testing/espresso/setup#analytics
  146. }
  147. splits {
  148. abi {
  149. enable true
  150. reset()
  151. include 'armeabi-v7a', 'x86', "arm64-v8a", "x86_64"
  152. exclude 'armeabi', 'mips', 'mips64'
  153. universalApk true
  154. }
  155. }
  156. // Assign different version code for each output
  157. project.ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, 'mips': 5, 'mips64': 6, 'x86': 8, 'x86_64': 9]
  158. android.applicationVariants.all { variant ->
  159. variant.outputs.each { output ->
  160. output.versionCodeOverride =
  161. project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1000000 + android.defaultConfig.versionCode
  162. }
  163. }
  164. flavorDimensions "default"
  165. productFlavors {
  166. none { }
  167. store_google { }
  168. store_threema {
  169. resValue "string", "shop_download_filename", "Threema-update.apk"
  170. }
  171. store_google_work {
  172. versionName "${app_version}k${beta_suffix}"
  173. applicationId "ch.threema.app.work"
  174. testApplicationId 'ch.threema.app.work.test'
  175. resValue "string", "app_name", "Threema Work"
  176. resValue "string", "contacts_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.work.profile"
  177. resValue "string", "call_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.work.call"
  178. buildConfigField "String", "CHAT_SERVER_PREFIX", "\"w-\""
  179. buildConfigField "String", "CHAT_SERVER_IPV6_PREFIX", "\"ds.w-\""
  180. buildConfigField "String", "MEDIA_PATH", "\"ThreemaWork\""
  181. buildConfigField "String", "WORK_SERVER_URL", "\"https://apip-work.threema.ch/\""
  182. buildConfigField "String", "WORK_SERVER_IPV6_URL", "\"https://ds-apip-work.threema.ch/\""
  183. // config fields for action URLs / deep links
  184. buildConfigField "String", "uriScheme", "\"threemawork\""
  185. buildConfigField "String", "actionUrl", "\"work.threema.ch\""
  186. manifestPlaceholders = [
  187. uriScheme: "threemawork",
  188. actionUrl: "work.threema.ch",
  189. ]
  190. }
  191. sandbox {
  192. applicationId "ch.threema.app.sandbox"
  193. testApplicationId 'ch.threema.app.sandbox.test'
  194. resValue "string", "app_name", "Threema Sandbox"
  195. buildConfigField "String", "MEDIA_PATH", "\"ThreemaSandbox\""
  196. buildConfigField "String", "CHAT_SERVER_SUFFIX", "\".0.test.threema.ch\""
  197. buildConfigField "byte[]", "SERVER_PUBKEY", "new byte[] {(byte) 0x5a, (byte) 0x98, (byte) 0xf2, (byte) 0x3d, (byte) 0xe6, (byte) 0x56, (byte) 0x05, (byte) 0xd0, (byte) 0x50, (byte) 0xdc, (byte) 0x00, (byte) 0x64, (byte) 0xbe, (byte) 0x07, (byte) 0xdd, (byte) 0xdd, (byte) 0x81, (byte) 0x1d, (byte) 0xa1, (byte) 0x16, (byte) 0xa5, (byte) 0x43, (byte) 0xce, (byte) 0x43, (byte) 0xaa, (byte) 0x26, (byte) 0x87, (byte) 0xd1, (byte) 0x9f, (byte) 0x20, (byte) 0xaf, (byte) 0x3c }"
  198. buildConfigField "byte[]", "SERVER_PUBKEY_ALT", "new byte[] {(byte) 0x5a, (byte) 0x98, (byte) 0xf2, (byte) 0x3d, (byte) 0xe6, (byte) 0x56, (byte) 0x05, (byte) 0xd0, (byte) 0x50, (byte) 0xdc, (byte) 0x00, (byte) 0x64, (byte) 0xbe, (byte) 0x07, (byte) 0xdd, (byte) 0xdd, (byte) 0x81, (byte) 0x1d, (byte) 0xa1, (byte) 0x16, (byte) 0xa5, (byte) 0x43, (byte) 0xce, (byte) 0x43, (byte) 0xaa, (byte) 0x26, (byte) 0x87, (byte) 0xd1, (byte) 0x9f, (byte) 0x20, (byte) 0xaf, (byte) 0x3c }"
  199. buildConfigField "String", "DIRECTORY_SERVER_URL", "\"https://apip.test.threema.ch/\""
  200. buildConfigField "String", "DIRECTORY_SERVER_IPV6_URL", "\"https://ds-apip.test.threema.ch/\""
  201. buildConfigField "String", "AVATAR_FETCH_URL", "\"https://avatar.test.threema.ch/\""
  202. }
  203. sandbox_work {
  204. versionName "${app_version}k${beta_suffix}"
  205. applicationId "ch.threema.app.sandbox.work"
  206. testApplicationId 'ch.threema.app.sandbox.work.test'
  207. resValue "string", "app_name", "Threema Sandbox Work"
  208. resValue "string", "contacts_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.work.profile"
  209. resValue "string", "call_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.work.call"
  210. buildConfigField "String", "CHAT_SERVER_PREFIX", "\"w-\""
  211. buildConfigField "String", "CHAT_SERVER_IPV6_PREFIX", "\"ds.w-\""
  212. buildConfigField "String", "CHAT_SERVER_SUFFIX", "\".0.test.threema.ch\""
  213. buildConfigField "String", "MEDIA_PATH", "\"ThreemaWorkSandbox\""
  214. buildConfigField "byte[]", "SERVER_PUBKEY", "new byte[] {(byte) 0x5a, (byte) 0x98, (byte) 0xf2, (byte) 0x3d, (byte) 0xe6, (byte) 0x56, (byte) 0x05, (byte) 0xd0, (byte) 0x50, (byte) 0xdc, (byte) 0x00, (byte) 0x64, (byte) 0xbe, (byte) 0x07, (byte) 0xdd, (byte) 0xdd, (byte) 0x81, (byte) 0x1d, (byte) 0xa1, (byte) 0x16, (byte) 0xa5, (byte) 0x43, (byte) 0xce, (byte) 0x43, (byte) 0xaa, (byte) 0x26, (byte) 0x87, (byte) 0xd1, (byte) 0x9f, (byte) 0x20, (byte) 0xaf, (byte) 0x3c }"
  215. buildConfigField "byte[]", "SERVER_PUBKEY_ALT", "new byte[] {(byte) 0x5a, (byte) 0x98, (byte) 0xf2, (byte) 0x3d, (byte) 0xe6, (byte) 0x56, (byte) 0x05, (byte) 0xd0, (byte) 0x50, (byte) 0xdc, (byte) 0x00, (byte) 0x64, (byte) 0xbe, (byte) 0x07, (byte) 0xdd, (byte) 0xdd, (byte) 0x81, (byte) 0x1d, (byte) 0xa1, (byte) 0x16, (byte) 0xa5, (byte) 0x43, (byte) 0xce, (byte) 0x43, (byte) 0xaa, (byte) 0x26, (byte) 0x87, (byte) 0xd1, (byte) 0x9f, (byte) 0x20, (byte) 0xaf, (byte) 0x3c }"
  216. buildConfigField "String", "DIRECTORY_SERVER_URL", "\"https://apip.test.threema.ch/\""
  217. buildConfigField "String", "DIRECTORY_SERVER_IPV6_URL", "\"https://ds-apip.test.threema.ch/\""
  218. buildConfigField "String", "WORK_SERVER_URL", "\"https://apip-work.test.threema.ch/\""
  219. buildConfigField "String", "WORK_SERVER_IPV6_URL", "\"https://ds-apip-work.test.threema.ch/\""
  220. buildConfigField "String", "AVATAR_FETCH_URL", "\"https://avatar.test.threema.ch/\""
  221. // config fields for action URLs / deep links
  222. buildConfigField "String", "uriScheme", "\"threemawork\""
  223. buildConfigField "String", "actionUrl", "\"work.threema.ch\""
  224. manifestPlaceholders = [
  225. uriScheme : "threemawork",
  226. actionUrl : "work.threema.ch",
  227. ]
  228. }
  229. onprem {
  230. versionName "${app_version}o${beta_suffix}"
  231. applicationId "ch.threema.app.onprem"
  232. testApplicationId 'ch.threema.app.onprem.test'
  233. resValue "string", "app_name", "Threema OnPrem"
  234. resValue "string", "contacts_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.onprem.profile"
  235. resValue "string", "call_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.onprem.call"
  236. buildConfigField "int", "MAX_GROUP_SIZE", "256"
  237. buildConfigField "String", "CHAT_SERVER_PREFIX", "\"\""
  238. buildConfigField "String", "CHAT_SERVER_IPV6_PREFIX", "\"\""
  239. buildConfigField "String", "CHAT_SERVER_SUFFIX", "null"
  240. buildConfigField "String", "MEDIA_PATH", "\"ThreemaOnPrem\""
  241. buildConfigField "boolean", "CHAT_SERVER_GROUPS", "false"
  242. buildConfigField "byte[]", "SERVER_PUBKEY", "null"
  243. buildConfigField "byte[]", "SERVER_PUBKEY_ALT", "null"
  244. buildConfigField "String", "DIRECTORY_SERVER_URL", "null"
  245. buildConfigField "String", "DIRECTORY_SERVER_IPV6_URL", "null"
  246. buildConfigField "String", "BLOB_SERVER_DOWNLOAD_URL", "null"
  247. buildConfigField "String", "BLOB_SERVER_DOWNLOAD_IPV6_URL", "null"
  248. buildConfigField "String", "BLOB_SERVER_DONE_URL", "null"
  249. buildConfigField "String", "BLOB_SERVER_DONE_IPV6_URL", "null"
  250. buildConfigField "String", "BLOB_SERVER_UPLOAD_URL", "null"
  251. buildConfigField "String", "BLOB_SERVER_UPLOAD_IPV6_URL", "null"
  252. buildConfigField "String[]", "ONPREM_CONFIG_TRUSTED_PUBLIC_KEYS", "new String[] {\"ek1qBp4DyRmLL9J5sCmsKSfwbsiGNB4veDAODjkwe/k=\", \"Hrk8aCjwKkXySubI7CZ3y9Sx+oToEHjNkGw98WSRneU=\", \"5pEn1T/5bhecNWrp9NgUQweRfgVtu/I8gRb3VxGP7k4=\"}"
  253. // config fields for action URLs / deep links
  254. buildConfigField "String", "uriScheme", "\"threemaonprem\""
  255. buildConfigField "String", "actionUrl", "\"onprem.threema.ch\""
  256. manifestPlaceholders = [
  257. uriScheme: "threemaonprem",
  258. actionUrl: "onprem.threema.ch",
  259. ]
  260. }
  261. red { // Essentially like sandbox work, but with a different icon and accent color, used for internal testing
  262. versionName "${app_version}r${beta_suffix}"
  263. applicationId "ch.threema.app.red"
  264. testApplicationId 'ch.threema.app.red.test'
  265. resValue "string", "app_name", "Threema Red"
  266. resValue "string", "contacts_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.redwork.profile"
  267. resValue "string", "call_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.redwork.call"
  268. buildConfigField "String", "CHAT_SERVER_PREFIX", "\"w-\""
  269. buildConfigField "String", "CHAT_SERVER_IPV6_PREFIX", "\"ds.w-\""
  270. buildConfigField "String", "CHAT_SERVER_SUFFIX", "\".0.test.threema.ch\""
  271. buildConfigField "String", "MEDIA_PATH", "\"ThreemaRed\""
  272. buildConfigField "byte[]", "SERVER_PUBKEY", "new byte[] {(byte) 0x5a, (byte) 0x98, (byte) 0xf2, (byte) 0x3d, (byte) 0xe6, (byte) 0x56, (byte) 0x05, (byte) 0xd0, (byte) 0x50, (byte) 0xdc, (byte) 0x00, (byte) 0x64, (byte) 0xbe, (byte) 0x07, (byte) 0xdd, (byte) 0xdd, (byte) 0x81, (byte) 0x1d, (byte) 0xa1, (byte) 0x16, (byte) 0xa5, (byte) 0x43, (byte) 0xce, (byte) 0x43, (byte) 0xaa, (byte) 0x26, (byte) 0x87, (byte) 0xd1, (byte) 0x9f, (byte) 0x20, (byte) 0xaf, (byte) 0x3c }"
  273. buildConfigField "byte[]", "SERVER_PUBKEY_ALT", "new byte[] {(byte) 0x5a, (byte) 0x98, (byte) 0xf2, (byte) 0x3d, (byte) 0xe6, (byte) 0x56, (byte) 0x05, (byte) 0xd0, (byte) 0x50, (byte) 0xdc, (byte) 0x00, (byte) 0x64, (byte) 0xbe, (byte) 0x07, (byte) 0xdd, (byte) 0xdd, (byte) 0x81, (byte) 0x1d, (byte) 0xa1, (byte) 0x16, (byte) 0xa5, (byte) 0x43, (byte) 0xce, (byte) 0x43, (byte) 0xaa, (byte) 0x26, (byte) 0x87, (byte) 0xd1, (byte) 0x9f, (byte) 0x20, (byte) 0xaf, (byte) 0x3c }"
  274. buildConfigField "String", "DIRECTORY_SERVER_URL", "\"https://apip.test.threema.ch/\""
  275. buildConfigField "String", "DIRECTORY_SERVER_IPV6_URL", "\"https://ds-apip.test.threema.ch/\""
  276. buildConfigField "String", "WORK_SERVER_URL", "\"https://apip-work.test.threema.ch/\""
  277. buildConfigField "String", "WORK_SERVER_IPV6_URL", "\"https://ds-apip-work.test.threema.ch/\""
  278. buildConfigField "String", "AVATAR_FETCH_URL", "\"https://avatar.test.threema.ch/\""
  279. buildConfigField "boolean", "SEND_CONSUMED_DELIVERY_RECEIPTS", "true"
  280. // config fields for action URLs / deep links
  281. buildConfigField "String", "uriScheme", "\"threemared\""
  282. buildConfigField "String", "actionUrl", "\"red.threema.ch\""
  283. manifestPlaceholders = [
  284. uriScheme: "threemared",
  285. actionUrl: "red.threema.ch",
  286. ]
  287. }
  288. hms {
  289. applicationId "ch.threema.app.hms"
  290. }
  291. hms_work {
  292. versionName "${app_version}k${beta_suffix}"
  293. applicationId "ch.threema.app.work.hms"
  294. testApplicationId 'ch.threema.app.work.test.hms'
  295. resValue "string", "app_name", "Threema Work"
  296. resValue "string", "contacts_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.work.profile"
  297. resValue "string", "call_mime_type", "vnd.android.cursor.item/vnd.ch.threema.app.work.call"
  298. buildConfigField "String", "CHAT_SERVER_PREFIX", "\"w-\""
  299. buildConfigField "String", "CHAT_SERVER_IPV6_PREFIX", "\"ds.w-\""
  300. buildConfigField "String", "MEDIA_PATH", "\"ThreemaWork\""
  301. buildConfigField "String", "WORK_SERVER_URL", "\"https://apip-work.threema.ch/\""
  302. buildConfigField "String", "WORK_SERVER_IPV6_URL", "\"https://ds-apip-work.threema.ch/\""
  303. // config fields for action URLs / deep links
  304. buildConfigField "String", "uriScheme", "\"threemawork\""
  305. buildConfigField "String", "actionUrl", "\"work.threema.ch\""
  306. manifestPlaceholders = [
  307. uriScheme: "threemawork",
  308. actionUrl: "work.threema.ch",
  309. ]
  310. }
  311. }
  312. signingConfigs {
  313. // Debug config
  314. if (keystores.debug != null) {
  315. debug {
  316. storeFile file(keystores.debug.storeFile)
  317. }
  318. } else {
  319. logger.warn("No debug keystore found. Falling back to locally generated keystore.")
  320. }
  321. // Release config
  322. if (keystores.release != null) {
  323. release {
  324. storeFile file(keystores.release.storeFile)
  325. storePassword keystores.release.storePassword
  326. keyAlias keystores.release.keyAlias
  327. keyPassword keystores.release.keyPassword
  328. }
  329. } else {
  330. logger.warn("No release keystore found. Falling back to locally generated keystore.")
  331. }
  332. // Release config
  333. if (keystores.hms_release != null) {
  334. hms_release {
  335. storeFile file(keystores.hms_release.storeFile)
  336. storePassword keystores.hms_release.storePassword
  337. keyAlias keystores.hms_release.keyAlias
  338. keyPassword keystores.hms_release.keyPassword
  339. }
  340. } else {
  341. logger.warn("No hms keystore found. Falling back to locally generated keystore.")
  342. }
  343. // Onprem release config
  344. if (keystores.onprem_release != null) {
  345. onprem_release {
  346. storeFile file(keystores.onprem_release.storeFile)
  347. storePassword keystores.onprem_release.storePassword
  348. keyAlias keystores.onprem_release.keyAlias
  349. keyPassword keystores.onprem_release.keyPassword
  350. }
  351. } else {
  352. logger.warn("No onprem keystore found. Falling back to locally generated keystore.")
  353. }
  354. // Red release config
  355. if (keystores.red_release != null) {
  356. red_release {
  357. storeFile file(keystores.red_release.storeFile)
  358. storePassword keystores.red_release.storePassword
  359. keyAlias keystores.red_release.keyAlias
  360. keyPassword keystores.red_release.keyPassword
  361. }
  362. } else {
  363. logger.warn("No red keystore found. Falling back to locally generated keystore.")
  364. }
  365. }
  366. sourceSets {
  367. main {
  368. assets.srcDirs = ['assets']
  369. jniLibs.srcDirs = ['libs']
  370. }
  371. none {
  372. java.srcDir 'src/google_services_based/java'
  373. }
  374. store_google {
  375. java.srcDir 'src/google_services_based/java'
  376. }
  377. store_google_work {
  378. java.srcDir 'src/google_services_based/java'
  379. }
  380. store_threema {
  381. java.srcDir 'src/google_services_based/java'
  382. }
  383. hms {
  384. java.srcDir 'src/hms_services_based/java'
  385. }
  386. hms_work {
  387. java.srcDir 'src/hms_services_based/java'
  388. res.srcDir 'src/store_google_work/res'
  389. }
  390. onprem {
  391. java.srcDir 'src/google_services_based/java'
  392. }
  393. sandbox {
  394. java.srcDir 'src/google_services_based/java'
  395. manifest.srcFile 'src/store_google/AndroidManifest.xml'
  396. }
  397. sandbox_work {
  398. java.srcDirs = ['src/store_google_work/java', 'src/google_services_based/java']
  399. res.srcDir 'src/store_google_work/res'
  400. manifest.srcFile 'src/store_google_work/AndroidManifest.xml'
  401. }
  402. red {
  403. java.srcDir 'src/google_services_based/java'
  404. res.srcDir 'src/red/res'
  405. }
  406. }
  407. buildTypes {
  408. debug {
  409. debuggable true
  410. jniDebuggable false
  411. multiDexEnabled true
  412. multiDexKeepProguard file('multidex-keep.pro')
  413. testCoverageEnabled false
  414. if (keystores['debug'] != null) {
  415. signingConfig signingConfigs.debug
  416. }
  417. }
  418. release {
  419. debuggable false
  420. jniDebuggable false
  421. minifyEnabled true
  422. shrinkResources false // Caused inconsistencies between local and CI builds
  423. zipAlignEnabled true
  424. multiDexEnabled true
  425. multiDexKeepProguard file('multidex-keep.pro')
  426. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt'
  427. if (keystores['release'] != null) {
  428. productFlavors.store_google.signingConfig signingConfigs.release
  429. productFlavors.store_google_work.signingConfig signingConfigs.release
  430. productFlavors.store_threema.signingConfig signingConfigs.release
  431. productFlavors.sandbox.signingConfig signingConfigs.release
  432. productFlavors.sandbox_work.signingConfig signingConfigs.release
  433. productFlavors.none.signingConfig signingConfigs.release
  434. }
  435. if (keystores['hms_release'] != null) {
  436. productFlavors.hms.signingConfig signingConfigs.hms_release
  437. productFlavors.hms_work.signingConfig signingConfigs.hms_release
  438. }
  439. if (keystores['onprem_release'] != null) {
  440. productFlavors.onprem.signingConfig signingConfigs.onprem_release
  441. }
  442. if (keystores['red_release'] != null) {
  443. productFlavors.red.signingConfig signingConfigs.red_release
  444. }
  445. }
  446. }
  447. // Only build relevant buildType / flavor combinations
  448. variantFilter { variant ->
  449. def names = variant.flavors*.name
  450. if (
  451. variant.buildType.name == "release" && (
  452. names.contains("sandbox") || names.contains("sandbox_work")
  453. )
  454. ) {
  455. setIgnore(true)
  456. }
  457. }
  458. externalNativeBuild {
  459. ndkBuild {
  460. path 'jni/Android.mk'
  461. }
  462. }
  463. lintOptions {
  464. // set to true to have all release builds run lint on issues with severity=fatal
  465. // and abort the build (controlled by abortOnError above) if fatal issues are found
  466. checkReleaseBuilds true
  467. // set to true to turn off analysis progress reporting by lint
  468. // quiet true
  469. // if true, stop the gradle build if errors are found
  470. abortOnError true
  471. // if true, only report errors
  472. ignoreWarnings false
  473. // if true, emit full/absolute paths to files with errors (true by default)
  474. //absolutePaths true
  475. // if true, check all issues, including those that are off by default
  476. checkAllWarnings true
  477. // if true, treat all warnings as errors
  478. warningsAsErrors false
  479. // turn off checking the given issue id's
  480. disable 'TypographyFractions', 'TypographyQuotes'
  481. // turn on the given issue id's
  482. disable 'RtlHardcoded', 'RtlCompat', 'RtlEnabled'
  483. // check *only* the given issue id's
  484. // check 'NewApi', 'InlinedApi'
  485. // if true, don't include source code lines in the error output
  486. noLines false
  487. // if true, show all locations for an error, do not truncate lists, etc.
  488. showAll true
  489. // if true, generate an XML report for use by for example Jenkins
  490. xmlReport true
  491. // file to write report to (if not specified, defaults to lint-results.xml)
  492. xmlOutput file("lint-report.xml")
  493. // Set the severity of the given issues to fatal (which means they will be
  494. // checked during release builds (even if the lint target is not included)
  495. fatal 'NewApi', 'InlinedApi'
  496. // Set the severity of the given issues to error
  497. error 'Wakelock', 'TextViewEdits', 'ResourceAsColor'
  498. // Set the severity of the given issues to warning
  499. warning 'MissingTranslation'
  500. // Set the severity of the given issues to ignore (same as disabling the check)
  501. ignore 'TypographyQuotes'
  502. }
  503. packagingOptions {
  504. exclude 'META-INF/DEPENDENCIES.txt'
  505. exclude 'META-INF/LICENSE.txt'
  506. exclude 'META-INF/NOTICE.txt'
  507. exclude 'META-INF/NOTICE'
  508. exclude 'META-INF/LICENSE'
  509. exclude 'META-INF/DEPENDENCIES'
  510. exclude 'META-INF/notice.txt'
  511. exclude 'META-INF/license.txt'
  512. exclude 'META-INF/dependencies.txt'
  513. exclude 'META-INF/LGPL2.1'
  514. exclude '**/*.proto'
  515. // fix https://stackoverflow.com/questions/42739916/aarch64-linux-android-strip-file-missing
  516. doNotStrip '*/mips/*.so'
  517. doNotStrip '*/mips64/*.so'
  518. doNotStrip '*/armeabi/*.so'
  519. }
  520. testOptions {
  521. // Disable animations in instrumentation tests
  522. animationsDisabled true
  523. unitTests {
  524. all {
  525. // All the usual Gradle options.
  526. testLogging {
  527. events "passed", "skipped", "failed", "standardOut", "standardError"
  528. outputs.upToDateWhen { false }
  529. exceptionFormat = 'full'
  530. }
  531. }
  532. // By default, local unit tests throw an exception any time the code you are testing tries to access
  533. // Android platform APIs (unless you mock Android dependencies yourself or with a testing
  534. // framework like Mockito). However, you can enable the following property so that the test
  535. // returns either null or zero when accessing platform APIs, rather than throwing an exception.
  536. returnDefaultValues true
  537. }
  538. }
  539. compileOptions {
  540. targetCompatibility 1.8
  541. sourceCompatibility 1.8
  542. }
  543. aaptOptions {
  544. noCompress 'png'
  545. }
  546. }
  547. dependencies {
  548. configurations.all {
  549. // Prefer modules that are part of this build (multi-project or composite build)
  550. // over external modules
  551. resolutionStrategy.preferProjectModules()
  552. // Alternatively, we can fail eagerly on version conflict to see the conflicts
  553. //resolutionStrategy.failOnVersionConflict()
  554. }
  555. implementation project(':domain')
  556. implementation 'net.zetetic:android-database-sqlcipher:4.4.3'
  557. implementation 'com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0'
  558. implementation 'net.sf.opencsv:opencsv:2.3'
  559. implementation 'net.lingala.zip4j:zip4j:2.9.0'
  560. implementation 'com.getkeepsafe.taptargetview:taptargetview:1.13.2'
  561. implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.2.1'
  562. // commons-io >2.6 requires android 8
  563. implementation 'commons-io:commons-io:2.6'
  564. implementation "org.slf4j:slf4j-api:$slf4j_version"
  565. implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.23'
  566. implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
  567. implementation 'com.datatheorem.android.trustkit:trustkit:1.1.5'
  568. implementation 'com.takisoft.preferencex:preferencex:1.1.0'
  569. implementation 'me.zhanghai.android.fastscroll:library:1.1.5'
  570. // AndroidX / Jetpack support libraries
  571. implementation "androidx.core:core:1.6.0"
  572. implementation "androidx.preference:preference:1.1.1"
  573. implementation 'androidx.recyclerview:recyclerview:1.2.1'
  574. implementation 'androidx.palette:palette:1.0.0'
  575. implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
  576. implementation 'androidx.appcompat:appcompat:1.3.1'
  577. implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
  578. implementation 'androidx.biometric:biometric:1.1.0'
  579. implementation "androidx.work:work-runtime:2.6.0"
  580. implementation 'androidx.fragment:fragment:1.3.6'
  581. implementation 'androidx.activity:activity:1.3.1'
  582. implementation 'androidx.sqlite:sqlite:2.1.0'
  583. implementation "androidx.concurrent:concurrent-futures:1.1.0"
  584. implementation "androidx.camera:camera-camera2:1.0.2"
  585. implementation "androidx.camera:camera-lifecycle:1.0.2"
  586. // camera-view >1.0.0-alpha25 requires compileSDK 30
  587. implementation "androidx.camera:camera-view:1.0.0-alpha25"
  588. implementation 'androidx.multidex:multidex:2.0.1'
  589. implementation "androidx.lifecycle:lifecycle-viewmodel:2.3.1"
  590. implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
  591. implementation "androidx.lifecycle:lifecycle-livedata:2.3.1"
  592. implementation "androidx.lifecycle:lifecycle-runtime:2.3.1"
  593. implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.1"
  594. implementation "androidx.lifecycle:lifecycle-service:2.3.1"
  595. implementation "androidx.lifecycle:lifecycle-process:2.3.1"
  596. implementation "androidx.lifecycle:lifecycle-common-java8:2.3.1"
  597. implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
  598. implementation "androidx.paging:paging-runtime:3.0.1"
  599. implementation 'com.google.android.material:material:1.4.0'
  600. implementation 'com.google.android.exoplayer:exoplayer-core:2.15.1'
  601. implementation 'com.google.android.exoplayer:exoplayer-ui:2.15.1'
  602. implementation 'com.google.zxing:core:3.3.3' // zxing 3.4 crashes on kitkat
  603. implementation 'com.googlecode.libphonenumber:libphonenumber:8.12.37'
  604. // webclient dependencies
  605. implementation 'org.msgpack:msgpack-core:0.8.22!!'
  606. implementation 'com.neovisionaries:nv-websocket-client:2.9'
  607. // Backport of Streams and CompletableFuture. Remove once API level 24 is supported.
  608. implementation 'net.sourceforge.streamsupport:streamsupport-cfuture:1.7.2'
  609. // Google Assistant Voice Action verification library
  610. implementation(name: 'libgsaverification-client', ext: 'aar')
  611. implementation('org.saltyrtc:saltyrtc-client:0.14.2') {
  612. exclude group: 'org.json'
  613. }
  614. implementation 'org.saltyrtc:chunked-dc:1.0.1'
  615. implementation 'ch.threema:webrtc-android:94.0.0'
  616. implementation('org.saltyrtc:saltyrtc-task-webrtc:0.18.1') {
  617. exclude module: 'saltyrtc-client'
  618. }
  619. // Glide components
  620. implementation 'com.github.bumptech.glide:glide:4.12.0'
  621. annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
  622. // kotlin
  623. implementation "androidx.core:core-ktx:1.3.2"
  624. implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
  625. implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3"
  626. // use leak canary in debug builds
  627. // debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.5'
  628. // test dependencies
  629. testImplementation 'junit:junit:4.12'
  630. testImplementation(testFixtures(project(":domain")))
  631. // use powermock instead of mockito. it support mocking static classes.
  632. def mockitoVersion = '2.0.7'
  633. testImplementation "org.powermock:powermock-api-mockito2:${mockitoVersion}"
  634. testImplementation "org.powermock:powermock-module-junit4-rule-agent:${mockitoVersion}"
  635. testImplementation "org.powermock:powermock-module-junit4-rule:${mockitoVersion}"
  636. testImplementation "org.powermock:powermock-module-junit4:${mockitoVersion}"
  637. // add JSON support to tests without mocking
  638. testImplementation 'org.json:json:20160212'
  639. testImplementation 'com.tngtech.archunit:archunit-junit4:0.18.0'
  640. androidTestImplementation(testFixtures(project(":domain")))
  641. androidTestImplementation 'androidx.test:rules:1.2.0'
  642. androidTestImplementation 'tools.fastlane:screengrab:2.0.0', {
  643. exclude group: 'androidx.annotation', module: 'annotation'
  644. }
  645. androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0', {
  646. exclude group: 'androidx.annotation', module: 'annotation'
  647. }
  648. androidTestImplementation 'androidx.test:runner:1.1.0', {
  649. exclude group: 'androidx.annotation', module: 'annotation'
  650. }
  651. androidTestImplementation 'androidx.test.ext:junit:1.1.1'
  652. androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0', {
  653. exclude group: 'androidx.annotation', module: 'annotation'
  654. exclude group: 'androidx.appcompat', module: 'appcompat'
  655. exclude group: 'androidx.legacy', module: 'legacy-support-v4'
  656. exclude group: 'com.google.android.material', module: 'material'
  657. exclude group: 'androidx.recyclerview', module: 'recyclerview'
  658. }
  659. androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0', {
  660. exclude group: 'androidx.annotation', module: 'annotation'
  661. }
  662. androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
  663. // Google Play Services and related libraries
  664. def googleDependencies = [
  665. // Play services
  666. 'com.google.android.gms:play-services-base:16.1.0': [],
  667. // Support for wearables
  668. 'com.google.android.gms:play-services-wearable:17.0.0': [],
  669. // Firebase push
  670. //
  671. // Note: Do not upgrade to a higher version of firebase-messaging,
  672. // as we do not want the Firebase Installations API in our app
  673. 'com.google.firebase:firebase-messaging:20.1.0': [
  674. [group: 'com.google.firebase', module: 'firebase-core'],
  675. [group: 'com.google.firebase', module: 'firebase-analytics'],
  676. [group: 'com.google.firebase', module: 'firebase-measurement-connector'],
  677. ],
  678. ]
  679. googleDependencies.each {
  680. def dependency = it.key
  681. def excludes = it.value
  682. noneImplementation(dependency) { excludes.each { exclude it } }
  683. store_googleImplementation(dependency) { excludes.each { exclude it } }
  684. store_google_workImplementation(dependency) { excludes.each { exclude it } }
  685. store_threemaImplementation(dependency) { excludes.each { exclude it } }
  686. onpremImplementation(dependency) { excludes.each { exclude it } }
  687. sandboxImplementation(dependency) { excludes.each { exclude it } }
  688. sandbox_workImplementation(dependency) { excludes.each { exclude it } }
  689. redImplementation(dependency) { excludes.each { exclude it } }
  690. }
  691. // Huawei related libraries (only for hms* build variants)
  692. def huaweiDependencies = [
  693. // HMS push
  694. 'com.huawei.hms:push:5.0.4.302': [
  695. // Exclude agconnect dependency, we'll replace it with the vendored version below
  696. [group: 'com.huawei.agconnect'],
  697. ],
  698. ]
  699. huaweiDependencies.each {
  700. def dependency = it.key
  701. def excludes = it.value
  702. hmsImplementation(dependency) { excludes.each { exclude it } }
  703. hms_workImplementation(dependency) { excludes.each { exclude it } }
  704. }
  705. hmsImplementation(name: 'agconnect-core-1.4.0.300', ext: 'aar')
  706. hms_workImplementation(name: 'agconnect-core-1.4.0.300', ext: 'aar')
  707. }
  708. sonarqube {
  709. properties {
  710. property "sonar.sources", "src/main/, ../scripts/, ../scripts-internal/"
  711. property "sonar.exclusions", "src/main/java/ch/threema/localcrypto/**, src/test/java/ch/threema/localcrypto/**"
  712. property "sonar.tests", "src/testNoneDebug/"
  713. property "sonar.sourceEncoding", "UTF-8"
  714. property "sonar.verbose", "true"
  715. property 'sonar.projectKey', 'android-client'
  716. property 'sonar.projectName', 'Threema for Android'
  717. }
  718. }
  719. // Set up Gradle tasks to fetch screenshots on UI test failures
  720. // See https://medium.com/stepstone-tech/how-to-capture-screenshots-for-failed-ui-tests-9927eea6e1e4
  721. def reportsDirectory = "$buildDir/reports/androidTests/connected"
  722. def screenshotsDirectory = "/sdcard/testfailures/screenshots/"
  723. def clearScreenshotsTask = task('clearScreenshots', type: Exec) {
  724. executable "${android.getAdbExe().toString()}"
  725. args 'shell', 'rm', '-r', screenshotsDirectory
  726. }
  727. def createScreenshotsDirectoryTask = task('createScreenshotsDirectory', type: Exec, group: 'reporting') {
  728. executable "${android.getAdbExe().toString()}"
  729. args 'shell', 'mkdir', '-p', screenshotsDirectory
  730. }
  731. def fetchScreenshotsTask = task('fetchScreenshots', type: Exec, group: 'reporting') {
  732. executable "${android.getAdbExe().toString()}"
  733. args 'pull', screenshotsDirectory + '.', reportsDirectory
  734. finalizedBy {
  735. clearScreenshotsTask
  736. }
  737. dependsOn {
  738. createScreenshotsDirectoryTask
  739. }
  740. doFirst {
  741. new File(reportsDirectory).mkdirs()
  742. }
  743. }
  744. tasks.whenTaskAdded { task ->
  745. if (task.name == 'connectedDebugAndroidTest') {
  746. task.finalizedBy {
  747. fetchScreenshotsTask
  748. }
  749. }
  750. }