build.gradle 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. import com.github.spotbugs.snom.SpotBugsTask
  2. import org.gradle.internal.jvm.Jvm
  3. buildscript {
  4. dependencies {
  5. classpath 'com.android.tools.build:gradle:7.3.1'
  6. classpath 'com.hiya:jacoco-android:0.2'
  7. classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.13'
  8. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  9. classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.22.0"
  10. classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  11. classpath 'com.karumi:shot:5.14.1'
  12. classpath "org.jacoco:org.jacoco.core:$jacoco_version"
  13. classpath "org.jacoco:org.jacoco.report:$jacoco_version"
  14. classpath "org.jacoco:org.jacoco.agent:$jacoco_version"
  15. }
  16. }
  17. plugins {
  18. id "com.diffplug.spotless" version "6.12.0"
  19. }
  20. apply plugin: 'com.android.application'
  21. apply plugin: 'kotlin-android'
  22. apply plugin: 'kotlin-kapt'
  23. apply plugin: 'kotlin-parcelize'
  24. apply plugin: 'checkstyle'
  25. apply plugin: 'pmd'
  26. apply plugin: 'com.hiya.jacoco-android'
  27. apply plugin: 'com.github.spotbugs'
  28. apply plugin: 'io.gitlab.arturbosch.detekt'
  29. apply plugin: 'shot'
  30. println "Gradle uses Java ${Jvm.current()}"
  31. configurations {
  32. all {
  33. exclude group: 'org.jetbrains', module: 'annotations-java5' // via prism4j, already using annotations explicitly
  34. // check for updates every build
  35. resolutionStrategy {
  36. cacheChangingModulesFor 0, 'seconds'
  37. exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug"
  38. }
  39. }
  40. }
  41. configurations.configureEach {
  42. resolutionStrategy.eachDependency {
  43. if (requested.group == "org.checkerframework" && requested.name != "checker-compat-qual") {
  44. useVersion(checkerVersion)
  45. because("https://github.com/google/ExoPlayer/issues/10007")
  46. }
  47. }
  48. }
  49. // semantic versioning for version code
  50. def versionMajor = 3
  51. def versionMinor = 24
  52. def versionPatch = 0
  53. def versionBuild = 0 // 0-50=Alpha / 51-98=RC / 90-99=stable
  54. def ndkEnv = new HashMap<String, String>()
  55. file("$project.rootDir/ndk.env").readLines().each() {
  56. def (key, value) = it.tokenize('=')
  57. ndkEnv.put(key, value)
  58. }
  59. def perfAnalysis = project.hasProperty('perfAnalysis')
  60. android {
  61. compileSdkVersion 32
  62. // install this NDK version and Cmake to produce smaller APKs. Build will still work if not installed
  63. ndkVersion "${ndkEnv.get("NDK_VERSION")}"
  64. namespace 'com.owncloud.android'
  65. testNamespace "${namespace}.test"
  66. defaultConfig {
  67. minSdkVersion 23
  68. targetSdkVersion 31
  69. buildConfigField 'boolean', 'CI', ciBuild.toString()
  70. buildConfigField 'boolean', 'RUNTIME_PERF_ANALYSIS', perfAnalysis.toString()
  71. javaCompileOptions {
  72. annotationProcessorOptions {
  73. arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
  74. }
  75. }
  76. // arguments to be passed to functional tests
  77. testInstrumentationRunner "com.nextcloud.client.ScreenshotTestRunner"
  78. testInstrumentationRunnerArgument "TEST_SERVER_URL", "${NC_TEST_SERVER_BASEURL}"
  79. testInstrumentationRunnerArgument "TEST_SERVER_USERNAME", "${NC_TEST_SERVER_USERNAME}"
  80. testInstrumentationRunnerArgument "TEST_SERVER_PASSWORD", "${NC_TEST_SERVER_PASSWORD}"
  81. testInstrumentationRunnerArguments disableAnalytics: 'true'
  82. multiDexEnabled true
  83. versionCode versionMajor * 10000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
  84. if (versionBuild > 89) {
  85. versionName "${versionMajor}.${versionMinor}.${versionPatch}"
  86. } else if (versionBuild > 50) {
  87. versionName "${versionMajor}.${versionMinor}.${versionPatch} RC" + (versionBuild - 50)
  88. } else {
  89. versionName "${versionMajor}.${versionMinor}.${versionPatch} Alpha" + (versionBuild + 1)
  90. }
  91. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  92. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  93. flavorDimensions "default"
  94. buildTypes {
  95. debug {
  96. testCoverageEnabled(project.hasProperty('coverage'))
  97. }
  98. }
  99. productFlavors {
  100. // used for f-droid
  101. generic {
  102. applicationId 'com.nextcloud.client'
  103. dimension "default"
  104. }
  105. gplay {
  106. applicationId 'com.nextcloud.client'
  107. dimension "default"
  108. }
  109. huawei {
  110. applicationId 'com.nextcloud.client'
  111. dimension "default"
  112. }
  113. versionDev {
  114. applicationId "com.nextcloud.android.beta"
  115. dimension "default"
  116. versionCode 20220322
  117. versionName "20220322"
  118. }
  119. qa {
  120. applicationId "com.nextcloud.android.qa"
  121. dimension "default"
  122. versionCode 1
  123. versionName "1"
  124. }
  125. }
  126. testOptions {
  127. unitTests.returnDefaultValues = true
  128. animationsDisabled true
  129. }
  130. }
  131. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  132. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  133. packagingOptions {
  134. resources {
  135. excludes += 'META-INF/LICENSE*'
  136. pickFirst 'MANIFEST.MF' // workaround for duplicated manifest on some dependencies
  137. }
  138. }
  139. tasks.register("checkstyle", Checkstyle) {
  140. configFile = file("${rootProject.projectDir}/checkstyle.xml")
  141. configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
  142. source 'src'
  143. include '**/*.java'
  144. exclude '**/gen/**'
  145. classpath = files()
  146. }
  147. tasks.register("pmd", Pmd) {
  148. ruleSetFiles = files("${project.rootDir}/ruleset.xml")
  149. ignoreFailures = true // should continue checking
  150. ruleSets = []
  151. source 'src'
  152. include '**/*.java'
  153. exclude '**/gen/**'
  154. reports {
  155. xml.enabled = false
  156. html.enabled = true
  157. xml {
  158. destination = file("$project.buildDir/reports/pmd/pmd.xml")
  159. }
  160. html {
  161. destination = file("$project.buildDir/reports/pmd/pmd.html")
  162. }
  163. }
  164. }
  165. check.dependsOn 'checkstyle', 'spotbugsGplayDebug', 'pmd', 'lint', 'spotlessKotlinCheck', 'detekt'
  166. buildFeatures {
  167. dataBinding true
  168. viewBinding true
  169. }
  170. kotlinOptions {
  171. jvmTarget = "1.8"
  172. }
  173. lint {
  174. abortOnError false
  175. checkGeneratedSources true
  176. disable 'MissingTranslation', 'GradleDependency', 'VectorPath', 'IconMissingDensityFolder', 'IconDensities', 'GoogleAppIndexingWarning', 'MissingDefaultResource', 'InvalidPeriodicWorkRequestInterval', 'StringFormatInvalid', 'MissingQuantity'
  177. htmlOutput file("$project.buildDir/reports/lint/lint.html")
  178. htmlReport true
  179. }
  180. }
  181. dependencies {
  182. // dependencies for app building
  183. implementation 'androidx.multidex:multidex:2.0.1'
  184. // implementation project('nextcloud-android-library')
  185. implementation("com.github.nextcloud:android-library:$androidLibraryVersion") {
  186. exclude group: 'org.ogce', module: 'xpp3' // unused in Android and brings wrong Junit version
  187. }
  188. compileOnly 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2' // remove after entire switch to lib v2
  189. implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  190. implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.5' // remove after entire switch to lib v2
  191. implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
  192. implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  193. implementation 'com.google.android.material:material:1.7.0'
  194. implementation 'com.jakewharton:disklrucache:2.0.2'
  195. implementation 'androidx.appcompat:appcompat:1.5.1'
  196. implementation 'androidx.webkit:webkit:1.5.0'
  197. implementation 'androidx.cardview:cardview:1.0.0'
  198. implementation 'androidx.exifinterface:exifinterface:1.3.5'
  199. implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
  200. implementation "androidx.work:work-runtime:$workRuntime"
  201. implementation "androidx.work:work-runtime-ktx:$workRuntime"
  202. implementation "androidx.fragment:fragment-ktx:1.5.5"
  203. implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
  204. compileOnly 'com.google.code.findbugs:annotations:3.0.1u2'
  205. implementation 'commons-io:commons-io:2.11.0'
  206. implementation 'org.greenrobot:eventbus:3.3.1'
  207. implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3'
  208. implementation 'org.lukhnos:nnio:0.2'
  209. implementation 'org.bouncycastle:bcpkix-jdk15to18:1.72'
  210. implementation 'com.google.code.gson:gson:2.10'
  211. implementation 'com.github.nextcloud-deps:sectioned-recyclerview:0.6.1'
  212. implementation 'com.github.chrisbanes:PhotoView:2.3.0'
  213. implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.25'
  214. implementation 'com.github.nextcloud-deps:qrcodescanner:0.1.2.4' // 'com.github.blikoon:QRCodeScanner:0.1.2'
  215. implementation 'com.google.android.flexbox:flexbox:3.0.0'
  216. implementation('com.github.bumptech.glide:glide:3.8.0') {
  217. exclude group: "com.android.support"
  218. }
  219. implementation 'com.caverock:androidsvg:1.4'
  220. implementation 'androidx.annotation:annotation:1.5.0'
  221. implementation 'com.vanniktech:emoji-google:0.9.0'
  222. implementation "com.github.nextcloud-deps.hwsecurity:hwsecurity-fido:$fidoVersion"
  223. implementation "com.github.nextcloud-deps.hwsecurity:hwsecurity-fido2:$fidoVersion"
  224. // document scanner not available on FDroid (generic) due to OpenCV binaries
  225. gplayImplementation "com.github.zynkware:Document-Scanning-Android-SDK:$documentScannerVersion"
  226. huaweiImplementation "com.github.zynkware:Document-Scanning-Android-SDK:$documentScannerVersion"
  227. qaImplementation "com.github.zynkware:Document-Scanning-Android-SDK:$documentScannerVersion"
  228. spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0'
  229. spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
  230. implementation "com.google.dagger:dagger:$daggerVersion"
  231. implementation "com.google.dagger:dagger-android:$daggerVersion"
  232. implementation "com.google.dagger:dagger-android-support:$daggerVersion"
  233. kapt "com.google.dagger:dagger-compiler:$daggerVersion"
  234. kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
  235. implementation 'org.conscrypt:conscrypt-android:2.5.2'
  236. implementation "com.google.android.exoplayer:exoplayer:$exoplayerVersion"
  237. implementation "com.google.android.exoplayer:extension-okhttp:$exoplayerVersion"
  238. implementation 'me.zhanghai.android.fastscroll:library:1.1.8'
  239. // Shimmer animation
  240. implementation 'io.github.elye:loaderviewlibrary:3.0.0'
  241. // dependencies for markdown rendering
  242. implementation "io.noties.markwon:core:$markwonVersion"
  243. implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
  244. implementation "io.noties.markwon:ext-tables:$markwonVersion"
  245. implementation "io.noties.markwon:ext-tasklist:$markwonVersion"
  246. implementation "io.noties.markwon:html:$markwonVersion"
  247. implementation "io.noties.markwon:syntax-highlight:$markwonVersion"
  248. implementation "io.noties:prism4j:$prismVersion"
  249. kapt "io.noties:prism4j-bundler:$prismVersion"
  250. implementation('org.mnode.ical4j:ical4j:3.0.0') {
  251. ['org.apache.commons', 'commons-logging'].each {
  252. exclude group: "$it"
  253. }
  254. }
  255. if (perfAnalysis) {
  256. debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10'
  257. }
  258. // dependencies for local unit tests
  259. testImplementation 'junit:junit:4.13.2'
  260. testImplementation "org.mockito:mockito-core:$mockitoVersion"
  261. testImplementation "androidx.test:core:$androidxTestVersion"
  262. testImplementation 'org.json:json:20220924'
  263. testImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion"
  264. testImplementation 'androidx.arch.core:core-testing:2.1.0'
  265. testImplementation "io.mockk:mockk:$mockkVersion"
  266. testImplementation "io.mockk:mockk-android:$mockkVersion"
  267. // dependencies for instrumented tests
  268. // JUnit4 Rules
  269. androidTestImplementation 'androidx.test.ext:junit:1.1.4'
  270. androidTestImplementation "androidx.test:rules:$androidxTestVersion"
  271. // Android JUnit Runner
  272. androidTestImplementation "androidx.test:runner:$androidxTestVersion"
  273. androidTestUtil "androidx.test:orchestrator:$androidxTestVersion"
  274. androidTestImplementation "androidx.test:core-ktx:$androidxTestVersion"
  275. // Espresso
  276. androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
  277. androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
  278. androidTestImplementation "androidx.test.espresso:espresso-web:$espressoVersion"
  279. androidTestImplementation "androidx.test.espresso:espresso-accessibility:$espressoVersion"
  280. androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
  281. // Mocking support
  282. androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5' // required to allow mocking on API 27 and older
  283. androidTestImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion"
  284. androidTestImplementation "org.mockito:mockito-core:$mockitoVersion"
  285. androidTestImplementation("org.mockito:mockito-android:$mockitoVersion")
  286. androidTestImplementation "io.mockk:mockk-android:$mockkVersion"
  287. androidTestImplementation 'androidx.arch.core:core-testing:2.0.1'
  288. androidTestImplementation "com.facebook.testing.screenshot:core:0.15.0"
  289. // UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
  290. // androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
  291. // fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
  292. //androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
  293. androidTestImplementation 'tools.fastlane:screengrab:2.1.1'
  294. implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  295. implementation "com.github.stateless4j:stateless4j:2.6.0"
  296. // upon each update first test: new registration, receive push
  297. gplayImplementation "com.google.firebase:firebase-messaging:23.1.1"
  298. implementation 'com.github.nextcloud.android-common:ui:0.3.0'
  299. implementation "androidx.room:room-runtime:$roomVersion"
  300. kapt "androidx.room:room-compiler:$roomVersion"
  301. }
  302. configurations.all {
  303. resolutionStrategy {
  304. cacheChangingModulesFor 0, 'seconds'
  305. force 'org.objenesis:objenesis:2.6'
  306. eachDependency { details ->
  307. if ('org.jacoco' == details.requested.group) {
  308. details.useVersion "$jacoco_version"
  309. }
  310. }
  311. }
  312. }
  313. tasks.withType(Test) {
  314. // increased logging for tests
  315. testLogging {
  316. events "passed", "skipped", "failed"
  317. }
  318. }
  319. android.applicationVariants.all { variant ->
  320. variant.outputs.all { output ->
  321. outputFileName = "${output.baseName}-${variant.versionCode}.apk"
  322. }
  323. }
  324. spotless {
  325. kotlin {
  326. target "**/*.kt"
  327. ktlint()
  328. }
  329. }
  330. detekt {
  331. reports {
  332. xml {
  333. enabled = false
  334. }
  335. }
  336. config = files("detekt.yml")
  337. }
  338. shot {
  339. showOnlyFailingTestsInReports = ciBuild
  340. // CI environment renders some shadows slightly different from local VMs
  341. // Add a 0.5% tolerance to account for that
  342. tolerance = ciBuild ? 0.5 : 0
  343. }
  344. jacoco {
  345. toolVersion = "$jacoco_version"
  346. }
  347. spotbugs {
  348. ignoreFailures = true // should continue checking
  349. effort = "max"
  350. reportLevel = "medium"
  351. }
  352. tasks.withType(SpotBugsTask) { task ->
  353. String variantNameCap = task.name.replace("spotbugs", "")
  354. String variantName = variantNameCap.substring(0, 1).toLowerCase() + variantNameCap.substring(1)
  355. dependsOn "compile${variantNameCap}Sources"
  356. excludeFilter = file("${project.rootDir}/spotbugs-filter.xml")
  357. classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/classes/")
  358. reports {
  359. xml {
  360. required = true
  361. }
  362. html {
  363. required = true
  364. outputLocation = file("$project.buildDir/reports/spotbugs/spotbugs.html")
  365. stylesheet = 'fancy.xsl'
  366. }
  367. }
  368. }