build.gradle 33 KB

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