build.gradle 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. /*
  2. * Nextcloud - Android Client
  3. *
  4. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
  6. * SPDX-FileCopyrightText: 2024 Tobias Kaminsky <tobias@kaminsky.me>
  7. * SPDX-FileCopyrightText: 2024 Andy Scherzinger <info@andy-scherzinger.de>
  8. * SPDX-FileCopyrightText: 2022 Álvaro Brey Vilas <alvaro@alvarobrey.com>
  9. * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
  10. */
  11. import com.github.spotbugs.snom.Confidence
  12. import com.github.spotbugs.snom.Effort
  13. import com.github.spotbugs.snom.SpotBugsTask
  14. import org.gradle.internal.jvm.Jvm
  15. buildscript {
  16. dependencies {
  17. classpath "com.android.tools.build:gradle:$androidPluginVersion"
  18. classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:6.0.26'
  19. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  20. classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.7"
  21. classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  22. classpath 'com.karumi:shot:6.1.0'
  23. classpath "org.jacoco:org.jacoco.core:$jacoco_version"
  24. classpath "org.jacoco:org.jacoco.report:$jacoco_version"
  25. classpath "org.jacoco:org.jacoco.agent:$jacoco_version"
  26. }
  27. }
  28. plugins {
  29. id "org.jetbrains.kotlin.plugin.compose" version "2.0.21"
  30. id "com.diffplug.spotless" version "6.25.0"
  31. id "org.jetbrains.kotlin.kapt" version "2.0.21"
  32. id 'com.google.devtools.ksp' version '2.0.21-1.0.27' apply false
  33. }
  34. apply plugin: 'com.android.application'
  35. apply plugin: 'kotlin-android'
  36. apply plugin: 'kotlin-parcelize'
  37. apply plugin: 'checkstyle'
  38. apply plugin: 'pmd'
  39. apply from: "$rootProject.projectDir/jacoco.gradle"
  40. apply plugin: 'com.github.spotbugs'
  41. apply plugin: 'io.gitlab.arturbosch.detekt'
  42. // needed to make renovate run without shot, as shot requires Android SDK
  43. // https://github.com/pedrovgs/Shot/issues/300
  44. if (shotTest) {
  45. apply plugin: 'shot'
  46. }
  47. apply plugin: 'com.google.devtools.ksp'
  48. println "Gradle uses Java ${Jvm.current()}"
  49. configurations {
  50. configureEach {
  51. exclude group: 'org.jetbrains', module: 'annotations-java5' // via prism4j, already using annotations explicitly
  52. // check for updates every build
  53. resolutionStrategy {
  54. cacheChangingModulesFor 0, 'seconds'
  55. exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug"
  56. }
  57. }
  58. }
  59. configurations.configureEach {
  60. resolutionStrategy.eachDependency {
  61. if (requested.group == "org.checkerframework" && requested.name != "checker-compat-qual") {
  62. useVersion(checkerVersion)
  63. because("https://github.com/google/ExoPlayer/issues/10007")
  64. }
  65. }
  66. }
  67. // semantic versioning for version code
  68. def versionMajor = 3
  69. def versionMinor = 30
  70. def versionPatch = 0
  71. def versionBuild = 0 // 0-50=Alpha / 51-98=RC / 90-99=stable
  72. def ndkEnv = new HashMap<String, String>()
  73. file("$project.rootDir/ndk.env").readLines().each() {
  74. def (key, value) = it.tokenize('=')
  75. ndkEnv.put(key, value)
  76. }
  77. def perfAnalysis = project.hasProperty('perfAnalysis')
  78. android {
  79. // install this NDK version and Cmake to produce smaller APKs. Build will still work if not installed
  80. ndkVersion "${ndkEnv.get("NDK_VERSION")}"
  81. namespace 'com.owncloud.android'
  82. testNamespace "${namespace}.test"
  83. androidResources {
  84. generateLocaleConfig = true
  85. }
  86. defaultConfig {
  87. applicationId "com.nextcloud.client"
  88. minSdkVersion 24
  89. targetSdkVersion 34
  90. compileSdk 34
  91. buildConfigField 'boolean', 'CI', ciBuild.toString()
  92. buildConfigField 'boolean', 'RUNTIME_PERF_ANALYSIS', perfAnalysis.toString()
  93. javaCompileOptions {
  94. annotationProcessorOptions {
  95. arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
  96. }
  97. }
  98. // arguments to be passed to functional tests
  99. if (shotTest) {
  100. testInstrumentationRunner "com.karumi.shot.ShotTestRunner"
  101. } else {
  102. testInstrumentationRunner "com.nextcloud.client.TestRunner"
  103. }
  104. testInstrumentationRunnerArgument "TEST_SERVER_URL", "${NC_TEST_SERVER_BASEURL}"
  105. testInstrumentationRunnerArgument "TEST_SERVER_USERNAME", "${NC_TEST_SERVER_USERNAME}"
  106. testInstrumentationRunnerArgument "TEST_SERVER_PASSWORD", "${NC_TEST_SERVER_PASSWORD}"
  107. testInstrumentationRunnerArguments disableAnalytics: 'true'
  108. versionCode versionMajor * 10000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
  109. if (versionBuild > 89) {
  110. versionName "${versionMajor}.${versionMinor}.${versionPatch}"
  111. } else if (versionBuild > 50) {
  112. versionName "${versionMajor}.${versionMinor}.${versionPatch} RC" + (versionBuild - 50)
  113. } else {
  114. versionName "${versionMajor}.${versionMinor}.${versionPatch} Alpha" + (versionBuild + 1)
  115. }
  116. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  117. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  118. flavorDimensions += "default"
  119. buildTypes {
  120. debug {
  121. testCoverageEnabled(project.hasProperty('coverage'))
  122. }
  123. }
  124. buildFeatures {
  125. buildConfig = true
  126. }
  127. productFlavors {
  128. // used for f-droid
  129. generic {
  130. applicationId 'com.nextcloud.client'
  131. dimension "default"
  132. }
  133. gplay {
  134. applicationId 'com.nextcloud.client'
  135. dimension "default"
  136. }
  137. huawei {
  138. applicationId 'com.nextcloud.client'
  139. dimension "default"
  140. }
  141. versionDev {
  142. applicationId "com.nextcloud.android.beta"
  143. dimension "default"
  144. versionCode 20220322
  145. versionName "20220322"
  146. }
  147. qa {
  148. applicationId "com.nextcloud.android.qa"
  149. dimension "default"
  150. versionCode 1
  151. versionName "1"
  152. }
  153. }
  154. testOptions {
  155. unitTests.returnDefaultValues = true
  156. animationsDisabled true
  157. }
  158. }
  159. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  160. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  161. packagingOptions {
  162. resources {
  163. excludes += 'META-INF/LICENSE*'
  164. excludes += 'META-INF/versions/9/OSGI-INF/MANIFEST*'
  165. pickFirst 'MANIFEST.MF' // workaround for duplicated manifest on some dependencies
  166. }
  167. }
  168. tasks.register("checkstyle", Checkstyle) {
  169. configFile = file("${rootProject.projectDir}/checkstyle.xml")
  170. configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
  171. source 'src'
  172. include '**/*.java'
  173. exclude '**/gen/**'
  174. classpath = files()
  175. }
  176. tasks.register("pmd", Pmd) {
  177. ruleSetFiles = files("${project.rootDir}/ruleset.xml")
  178. ignoreFailures = true // should continue checking
  179. ruleSets = []
  180. source 'src'
  181. include '**/*.java'
  182. exclude '**/gen/**'
  183. reports {
  184. xml {
  185. destination = file("$project.buildDir/reports/pmd/pmd.xml")
  186. }
  187. html {
  188. destination = file("$project.buildDir/reports/pmd/pmd.html")
  189. }
  190. }
  191. }
  192. check.dependsOn 'checkstyle', 'spotbugsGplayDebug', 'pmd', 'lint', 'spotlessKotlinCheck', 'detekt'
  193. buildFeatures {
  194. dataBinding true
  195. viewBinding true
  196. aidl true
  197. compose = true
  198. }
  199. compileOptions {
  200. sourceCompatibility JavaVersion.VERSION_17
  201. targetCompatibility JavaVersion.VERSION_17
  202. }
  203. kotlinOptions {
  204. jvmTarget = "17"
  205. }
  206. lint {
  207. abortOnError false
  208. checkGeneratedSources true
  209. disable 'MissingTranslation', 'GradleDependency', 'VectorPath', 'IconMissingDensityFolder', 'IconDensities', 'GoogleAppIndexingWarning', 'MissingDefaultResource', 'InvalidPeriodicWorkRequestInterval', 'StringFormatInvalid', 'MissingQuantity'
  210. htmlOutput file("$project.buildDir/reports/lint/lint.html")
  211. htmlReport true
  212. }
  213. sourceSets {
  214. // Adds exported schema location as test app assets.
  215. androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
  216. }
  217. }
  218. dependencies {
  219. implementation("com.github.nextcloud:android-library:$androidLibraryVersion") {
  220. exclude group: 'org.ogce', module: 'xpp3' // unused in Android and brings wrong Junit version
  221. }
  222. // Jetpack Compose
  223. implementation(platform("androidx.compose:compose-bom:2024.11.00"))
  224. implementation("androidx.compose.ui:ui")
  225. implementation("androidx.compose.ui:ui-graphics")
  226. implementation("androidx.compose.material3:material3")
  227. debugImplementation("androidx.compose.ui:ui-tooling")
  228. implementation("androidx.compose.ui:ui-tooling-preview")
  229. compileOnly 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
  230. // remove after entire switch to lib v2
  231. implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  232. implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.5' // remove after entire switch to lib v2
  233. implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
  234. implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  235. implementation 'com.google.android.material:material:1.12.0'
  236. implementation 'com.jakewharton:disklrucache:2.0.2'
  237. implementation "androidx.appcompat:appcompat:$appCompatVersion"
  238. implementation 'androidx.webkit:webkit:1.12.1'
  239. implementation 'androidx.cardview:cardview:1.0.0'
  240. implementation 'androidx.exifinterface:exifinterface:1.3.7'
  241. implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.7"
  242. implementation "androidx.lifecycle:lifecycle-service:2.8.7"
  243. implementation "androidx.work:work-runtime:$workRuntime"
  244. implementation "androidx.work:work-runtime-ktx:$workRuntime"
  245. implementation "androidx.fragment:fragment-ktx:1.8.5"
  246. implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
  247. compileOnly 'com.google.code.findbugs:annotations:3.0.1u2'
  248. implementation 'commons-io:commons-io:2.18.0'
  249. implementation 'org.greenrobot:eventbus:3.3.1'
  250. implementation 'com.googlecode.ez-vcard:ez-vcard:0.12.1'
  251. implementation 'org.lukhnos:nnio:0.3.1'
  252. implementation 'org.bouncycastle:bcpkix-jdk18on:1.78.1'
  253. implementation 'com.google.code.gson:gson:2.11.0'
  254. implementation 'com.github.nextcloud-deps:sectioned-recyclerview:0.6.1'
  255. implementation 'com.github.chrisbanes:PhotoView:2.3.0'
  256. implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.29'
  257. implementation 'com.github.nextcloud-deps:qrcodescanner:0.1.2.4' // 'com.github.blikoon:QRCodeScanner:0.1.2'
  258. implementation 'com.google.android.flexbox:flexbox:3.0.0'
  259. implementation('com.github.bumptech.glide:glide:3.8.0') {
  260. exclude group: "com.android.support"
  261. }
  262. implementation 'com.caverock:androidsvg:1.4'
  263. implementation 'androidx.annotation:annotation:1.9.1'
  264. implementation 'com.vanniktech:emoji-google:0.21.0'
  265. implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.7")
  266. // document scanner not available on FDroid (generic) due to OpenCV binaries
  267. gplayImplementation project(':appscan')
  268. huaweiImplementation project(':appscan')
  269. qaImplementation project(':appscan')
  270. spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.13.0'
  271. spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.6.8'
  272. implementation "com.google.dagger:dagger:$daggerVersion"
  273. implementation "com.google.dagger:dagger-android:$daggerVersion"
  274. implementation "com.google.dagger:dagger-android-support:$daggerVersion"
  275. kapt "com.google.dagger:dagger-compiler:$daggerVersion"
  276. kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
  277. implementation 'org.conscrypt:conscrypt-android:2.5.3'
  278. implementation "androidx.media3:media3-ui:$androidxMediaVersion"
  279. implementation "androidx.media3:media3-session:$androidxMediaVersion"
  280. implementation "androidx.media3:media3-exoplayer:$androidxMediaVersion"
  281. implementation "androidx.media3:media3-datasource-okhttp:$androidxMediaVersion"
  282. implementation 'me.zhanghai.android.fastscroll:library:1.3.0'
  283. // Shimmer animation
  284. implementation 'io.github.elye:loaderviewlibrary:3.0.0'
  285. // dependencies for markdown rendering
  286. implementation "io.noties.markwon:core:$markwonVersion"
  287. implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
  288. implementation "io.noties.markwon:ext-tables:$markwonVersion"
  289. implementation "io.noties.markwon:ext-tasklist:$markwonVersion"
  290. implementation "io.noties.markwon:html:$markwonVersion"
  291. implementation "io.noties.markwon:syntax-highlight:$markwonVersion"
  292. implementation "io.noties:prism4j:$prismVersion"
  293. kapt "io.noties:prism4j-bundler:$prismVersion"
  294. // dependencies for image cropping and rotation
  295. implementation 'com.vanniktech:android-image-cropper:4.6.0'
  296. implementation 'org.osmdroid:osmdroid-android:6.1.20'
  297. implementation('org.mnode.ical4j:ical4j:3.0.0') {
  298. ['org.apache.commons', 'commons-logging'].each {
  299. exclude group: "$it"
  300. }
  301. }
  302. if (perfAnalysis) {
  303. debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.14'
  304. }
  305. // dependencies for local unit tests
  306. testImplementation 'junit:junit:4.13.2'
  307. testImplementation "org.mockito:mockito-core:$mockitoVersion"
  308. testImplementation "androidx.test:core:$androidxTestVersion"
  309. testImplementation 'org.json:json:20240303'
  310. testImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion"
  311. testImplementation 'androidx.arch.core:core-testing:2.2.0'
  312. testImplementation "io.mockk:mockk:$mockkVersion"
  313. testImplementation "io.mockk:mockk-android:$mockkVersion"
  314. // dependencies for instrumented tests
  315. // JUnit4 Rules
  316. androidTestImplementation 'androidx.test.ext:junit:1.2.1'
  317. androidTestImplementation "androidx.test:rules:$androidxTestVersion"
  318. // Android JUnit Runner
  319. androidTestImplementation "androidx.test:runner:1.6.2"
  320. androidTestUtil "androidx.test:orchestrator:1.5.1"
  321. androidTestImplementation "androidx.test:core-ktx:$androidxTestVersion"
  322. // Espresso
  323. androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
  324. androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
  325. androidTestImplementation "androidx.test.espresso:espresso-web:$espressoVersion"
  326. androidTestImplementation "androidx.test.espresso:espresso-accessibility:$espressoVersion"
  327. androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
  328. androidTestImplementation "androidx.test.espresso:espresso-idling-resource:$espressoVersion"
  329. // Mocking support
  330. androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5' // required to allow mocking on API 27 and older
  331. androidTestImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion"
  332. androidTestImplementation "org.mockito:mockito-core:$mockitoVersion"
  333. androidTestImplementation("org.mockito:mockito-android:$mockitoVersion")
  334. androidTestImplementation "io.mockk:mockk-android:$mockkVersion"
  335. androidTestImplementation 'androidx.arch.core:core-testing:2.2.0'
  336. androidTestImplementation "com.facebook.testing.screenshot:core:0.15.0"
  337. // UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
  338. // androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
  339. // fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
  340. //androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
  341. androidTestImplementation 'tools.fastlane:screengrab:2.1.1'
  342. implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  343. implementation "com.github.stateless4j:stateless4j:2.6.0"
  344. // upon each update first test: new registration, receive push
  345. gplayImplementation "com.google.firebase:firebase-messaging:24.1.0"
  346. gplayImplementation 'com.google.android.gms:play-services-base:18.5.0'
  347. gplayImplementation 'com.google.android.play:review-ktx:2.0.2'
  348. implementation 'com.github.nextcloud.android-common:ui:0.23.2'
  349. implementation "androidx.room:room-runtime:$roomVersion"
  350. ksp "androidx.room:room-compiler:$roomVersion"
  351. androidTestImplementation "androidx.room:room-testing:$roomVersion"
  352. implementation "io.coil-kt:coil:2.7.0"
  353. // splash screen dependency ref: https://developer.android.com/develop/ui/views/launch/splash-screen/migrate
  354. implementation 'androidx.core:core-splashscreen:1.0.1'
  355. }
  356. configurations.configureEach {
  357. resolutionStrategy {
  358. cacheChangingModulesFor 0, 'seconds'
  359. force 'org.objenesis:objenesis:3.4'
  360. eachDependency { details ->
  361. if ('org.jacoco' == details.requested.group) {
  362. details.useVersion "$jacoco_version"
  363. }
  364. }
  365. }
  366. }
  367. tasks.withType(Test).configureEach {
  368. // increased logging for tests
  369. testLogging {
  370. events "passed", "skipped", "failed"
  371. }
  372. }
  373. android.applicationVariants.configureEach { variant ->
  374. variant.outputs.configureEach { output -> outputFileName = "${output.baseName}-${variant.versionCode}.apk"
  375. }
  376. }
  377. spotless {
  378. kotlin {
  379. target "**/*.kt"
  380. ktlint()
  381. }
  382. }
  383. detekt {
  384. config.setFrom("detekt.yml")
  385. }
  386. if (shotTest) {
  387. shot {
  388. showOnlyFailingTestsInReports = ciBuild
  389. // CI environment renders some shadows slightly different from local VMs
  390. // Add a 0.5% tolerance to account for that
  391. tolerance = ciBuild ? 0.1 : 0
  392. }
  393. }
  394. jacoco {
  395. toolVersion = "$jacoco_version"
  396. }
  397. spotbugs {
  398. ignoreFailures = true // should continue checking
  399. effort = Effort.MAX
  400. reportLevel = Confidence.valueOf('MEDIUM')
  401. }
  402. tasks.withType(SpotBugsTask){task ->
  403. String variantNameCap = task.name.replace("spotbugs", "")
  404. String variantName = variantNameCap.substring(0, 1).toLowerCase() + variantNameCap.substring(1)
  405. dependsOn "compile${variantNameCap}Sources"
  406. classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/compile${variantNameCap}JavaWithJavac/classes/")
  407. excludeFilter = file("${project.rootDir}/scripts/analysis/spotbugs-filter.xml")
  408. reports {
  409. xml {
  410. required = true
  411. }
  412. html {
  413. required = true
  414. outputLocation = file("$project.buildDir/reports/spotbugs/spotbugs.html")
  415. stylesheet = 'fancy.xsl'
  416. }
  417. }
  418. }
  419. ksp {
  420. arg('room.schemaLocation', "$projectDir/schemas")
  421. }