build.gradle 34 KB

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