build.gradle 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. apply plugin: 'com.android.application'
  2. apply plugin: 'witness'
  3. apply from: 'witness.gradle'
  4. def getStdout = { command, defaultValue ->
  5. def stdout = new ByteArrayOutputStream()
  6. try {
  7. exec {
  8. commandLine = command
  9. standardOutput = stdout
  10. }
  11. return stdout.toString().trim()
  12. } catch (Exception ignored) {
  13. return defaultValue
  14. }
  15. }
  16. android {
  17. compileSdkVersion 33
  18. buildToolsVersion '33.0.0'
  19. packagingOptions {
  20. doNotStrip '**/*.so'
  21. }
  22. defaultConfig {
  23. minSdkVersion 16
  24. targetSdkVersion 31
  25. versionCode 10423
  26. versionName "1.4.23"
  27. applicationId "org.briarproject.briar.android"
  28. buildConfigField "String", "TorVersion", "\"$tor_version\""
  29. vectorDrawables.useSupportLibrary = true
  30. buildConfigField "String", "GitHash",
  31. "\"${getStdout(['git', 'rev-parse', '--short=7', 'HEAD'], 'No commit hash')}\""
  32. def now = (long) (System.currentTimeMillis() / 1000)
  33. buildConfigField "Long", "BuildTimestamp",
  34. "${getStdout(['git', 'log', '-n', '1', '--format=%ct'], now)}000L"
  35. testInstrumentationRunner 'org.briarproject.briar.android.BriarTestRunner'
  36. testInstrumentationRunnerArguments disableAnalytics: 'true'
  37. }
  38. buildTypes {
  39. debug {
  40. applicationIdSuffix ".debug"
  41. shrinkResources false
  42. minifyEnabled true
  43. crunchPngs false
  44. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
  45. testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt', 'proguard-test.txt'
  46. }
  47. release {
  48. shrinkResources false
  49. minifyEnabled true
  50. crunchPngs false
  51. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
  52. }
  53. }
  54. flavorDimensions "version"
  55. productFlavors {
  56. screenshot {
  57. dimension "version"
  58. minSdkVersion 21
  59. applicationIdSuffix ".screenshot" // = org.briarproject.briar.android.screenshot.debug
  60. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt', 'proguard-test.txt'
  61. }
  62. official {
  63. dimension "version"
  64. }
  65. }
  66. variantFilter { variant ->
  67. if (variant.flavors*.name.contains("screenshot") && variant.buildType.name == "release") {
  68. setIgnore(true)
  69. }
  70. }
  71. compileOptions {
  72. sourceCompatibility JavaVersion.VERSION_1_8
  73. targetCompatibility JavaVersion.VERSION_1_8
  74. }
  75. testOptions {
  76. execution 'ANDROIDX_TEST_ORCHESTRATOR'
  77. unitTests {
  78. includeAndroidResources = true
  79. }
  80. }
  81. lintOptions {
  82. warning 'MissingTranslation'
  83. warning 'ImpliedQuantity'
  84. warning 'ExtraTranslation'
  85. // FIXME
  86. warning 'InvalidPackage'
  87. }
  88. }
  89. dependencies {
  90. // In theory this dependency shouldn't be needed, but without it Android Studio's linter will
  91. // complain about unresolved symbols for bramble-api test classes in briar-android tests,
  92. // even though the bramble-api test classes are provided by the testImplementation dependency
  93. // below and the compiler can find them
  94. implementation project(':bramble-api')
  95. implementation project(':bramble-core')
  96. implementation project(':bramble-android')
  97. implementation project(':briar-core')
  98. implementation 'androidx.fragment:fragment:1.3.4'
  99. implementation 'androidx.preference:preference:1.1.1'
  100. implementation 'androidx.exifinterface:exifinterface:1.3.3'
  101. implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
  102. implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
  103. implementation 'com.google.android.material:material:1.3.0'
  104. implementation 'androidx.recyclerview:recyclerview-selection:1.1.0'
  105. implementation 'org.briarproject:dont-kill-me-lib:0.2.5'
  106. implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
  107. implementation "org.jsoup:jsoup:$jsoup_version"
  108. implementation 'info.guardianproject.panic:panic:1.0'
  109. implementation 'de.hdodenhof:circleimageview:3.1.0'
  110. implementation 'com.google.zxing:core:3.3.3' // newer version need minSdk 24
  111. implementation 'uk.co.samuelwall:material-tap-target-prompt:3.3.0'
  112. implementation 'com.vanniktech:emoji-google:0.7.0' // newer versions need minSdk 21
  113. implementation 'com.github.kobakei:MaterialFabSpeedDial:1.2.1'
  114. implementation 'com.github.chrisbanes:PhotoView:2.3.0'
  115. def glideVersion = '4.12.0'
  116. implementation("com.github.bumptech.glide:glide:$glideVersion") {
  117. exclude group: 'com.android.support'
  118. exclude module: 'disklrucache' // when there's no disk cache, we can't accidentally use it
  119. }
  120. implementation 'org.nanohttpd:nanohttpd:2.3.1'
  121. annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
  122. annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"
  123. compileOnly 'javax.annotation:jsr250-api:1.0'
  124. testImplementation project(path: ':bramble-api', configuration: 'testOutput')
  125. testImplementation project(path: ':bramble-core', configuration: 'testOutput')
  126. def espressoVersion = '3.3.0'
  127. testImplementation 'androidx.test:runner:1.4.0'
  128. testImplementation 'androidx.test.ext:junit:1.1.3'
  129. testImplementation 'androidx.fragment:fragment-testing:1.4.0'
  130. testImplementation "androidx.arch.core:core-testing:2.1.0"
  131. testImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
  132. testImplementation 'org.robolectric:robolectric:4.4'
  133. testImplementation 'org.mockito:mockito-core:3.9.0'
  134. testImplementation "junit:junit:$junit_version"
  135. testImplementation "org.jmock:jmock:$jmock_version"
  136. testImplementation "org.jmock:jmock-junit4:$jmock_version"
  137. testImplementation "org.jmock:jmock-imposters:$jmock_version"
  138. testAnnotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
  139. androidTestImplementation project(path: ':bramble-api', configuration: 'testOutput')
  140. androidTestImplementation 'androidx.test.ext:junit:1.1.3'
  141. androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
  142. androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
  143. androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
  144. androidTestImplementation 'androidx.test:runner:1.3.0'
  145. androidTestImplementation "junit:junit:$junit_version"
  146. androidTestUtil 'androidx.test:orchestrator:1.3.0'
  147. androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
  148. androidTestCompileOnly 'javax.annotation:jsr250-api:1.0'
  149. androidTestScreenshotImplementation 'tools.fastlane:screengrab:2.1.1'
  150. androidTestScreenshotImplementation 'com.jraska:falcon:2.2.0'
  151. androidTestScreenshotImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
  152. }
  153. task verifyTranslations {
  154. doLast {
  155. def file = project.file("src/main/res/values/arrays.xml")
  156. def arrays = new XmlParser().parse(file)
  157. def lc = arrays.children().find { it.@name == "pref_language_values" }
  158. def translations = []
  159. lc.children().each { value -> translations.add(value.text()) }
  160. def folders = ["default", "en-US"]
  161. def exceptions = ["values-night", "values-v21", "values-v31", "values-ldrtl"]
  162. project.file("src/main/res").eachDir { dir ->
  163. if (dir.name.startsWith("values-") && !exceptions.contains(dir.name)) {
  164. folders.add(dir.name.substring(7).replace("-r", "-"))
  165. }
  166. }
  167. folders.each { n ->
  168. if (!translations.remove(n) && n != 'iw') {
  169. throw new GradleException("Translation " + n + " is missing in $file")
  170. }
  171. }
  172. if (translations.size() != 0)
  173. throw new GradleException("Translations\n" + translations.join("\n")
  174. + "\nhave no matching value folder")
  175. // Some devices use iw instead of he for hebrew
  176. def hebrew_legacy = project.file("src/main/res/values-iw")
  177. def hebrew = project.file("src/main/res/values-he")
  178. // Copy values-he to values-iw
  179. if (hebrew.exists()) {
  180. hebrew_legacy.mkdir()
  181. copy {
  182. from hebrew.getAbsolutePath()
  183. into hebrew_legacy.getAbsolutePath()
  184. }
  185. }
  186. }
  187. }
  188. project.afterEvaluate {
  189. preBuild.dependsOn.add(verifyTranslations)
  190. }