build.gradle 18 KB

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