build.gradle 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. import com.github.spotbugs.snom.SpotBugsTask
  2. // Gradle build file
  3. //
  4. // This project was started in Eclipse and later moved to Android Studio. In the transition, both IDEs were supported.
  5. // Due to this, the files layout is not the usual in new projects created with Android Studio / gradle. This file
  6. // merges declarations usually split in two separates build.gradle file, one for global settings of the project in
  7. // its root folder, another one for the app module in subfolder of root.
  8. buildscript {
  9. ext.kotlin_version = '1.4.10'
  10. repositories {
  11. google()
  12. jcenter()
  13. maven {
  14. url 'https://oss.sonatype.org/content/repositories/snapshots/'
  15. }
  16. maven {
  17. url 'https://plugins.gradle.org/m2/'
  18. }
  19. mavenCentral()
  20. }
  21. dependencies {
  22. classpath 'com.android.tools.build:gradle:4.1.1'
  23. classpath('com.hiya:jacoco-android:0.2')
  24. classpath 'gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.6.0'
  25. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  26. classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.14.2"
  27. classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  28. classpath 'com.karumi:shot:5.3.0'
  29. }
  30. }
  31. apply plugin: 'com.android.application'
  32. apply plugin: 'kotlin-android'
  33. apply plugin: 'kotlin-android-extensions'
  34. apply plugin: 'kotlin-kapt'
  35. apply plugin: 'checkstyle'
  36. apply plugin: 'pmd'
  37. apply plugin: 'com.hiya.jacoco-android'
  38. apply plugin: 'com.github.spotbugs'
  39. apply plugin: 'io.gitlab.arturbosch.detekt'
  40. apply plugin: 'shot'
  41. configurations {
  42. ktlint
  43. all {
  44. exclude group: 'org.jetbrains', module: 'annotations-java5' // via prism4j, already using annotations explicitly
  45. // check for updates every build
  46. resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
  47. }
  48. }
  49. ext {
  50. jacocoVersion = "0.8.2"
  51. daggerVersion = "2.29.1"
  52. markwonVersion = "4.6.0"
  53. prismVersion = "2.0.0"
  54. butterknifeVersion = "10.2.3"
  55. androidLibraryVersion = "master-SNAPSHOT"
  56. mockitoVersion = "3.6.0"
  57. mockkVersion = "1.10.2"
  58. powermockVersion = "2.0.9"
  59. byteBuddyVersion = "1.10.18"
  60. espressoVersion = "3.3.0"
  61. travisBuild = System.getenv("TRAVIS") == "true"
  62. // allows for -D pre-dex=false to be set
  63. preDexEnabled = "true" == System.getProperty("pre-dex", "true")
  64. }
  65. repositories {
  66. google()
  67. jcenter()
  68. maven { url "https://jitpack.io" }
  69. maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
  70. flatDir {
  71. dirs 'libs'
  72. }
  73. }
  74. // semantic versioning for version code
  75. def versionMajor = 3
  76. def versionMinor = 15
  77. def versionPatch = 0
  78. def versionBuild = 0 // 0-50=Alpha / 51-98=RC / 90-99=stable
  79. def testMinSdk = 21
  80. for (TaskExecutionRequest tr : getGradle().getStartParameter().getTaskRequests()) {
  81. for (String arg : tr.args) {
  82. // any gplay, but only exact "build", as e.g. buildGeneric shall not apply gplay.grade
  83. if (arg.contains("Gplay") || arg.contains("lint") || arg.contains("ExecuteScreenshot") || arg == "build") {
  84. apply from: 'gplay.gradle'
  85. System.console().println("Applying gplay.gradle")
  86. }
  87. if (arg.contains("lint")) {
  88. testMinSdk = 19
  89. }
  90. }
  91. }
  92. android {
  93. lintOptions {
  94. checkGeneratedSources = true
  95. abortOnError false
  96. htmlReport true
  97. htmlOutput file("$project.buildDir/reports/lint/lint.html")
  98. disable 'MissingTranslation',
  99. 'GradleDependency',
  100. 'VectorPath',
  101. 'IconMissingDensityFolder',
  102. 'IconDensities',
  103. 'GoogleAppIndexingWarning',
  104. 'MissingDefaultResource',
  105. 'InvalidPeriodicWorkRequestInterval' // crashes due to a bug in lint itself
  106. }
  107. dexOptions {
  108. javaMaxHeapSize "4g"
  109. }
  110. compileSdkVersion 29
  111. defaultConfig {
  112. minSdkVersion 19
  113. targetSdkVersion 29
  114. // arguments to be passed to functional tests
  115. testInstrumentationRunner "com.nextcloud.client.ScreenshotTestRunner"
  116. testInstrumentationRunnerArgument "TEST_SERVER_URL", "${NC_TEST_SERVER_BASEURL}"
  117. testInstrumentationRunnerArgument "TEST_SERVER_USERNAME", "${NC_TEST_SERVER_USERNAME}"
  118. testInstrumentationRunnerArgument "TEST_SERVER_PASSWORD", "${NC_TEST_SERVER_PASSWORD}"
  119. testInstrumentationRunnerArguments disableAnalytics: 'true'
  120. multiDexEnabled true
  121. versionCode versionMajor * 10000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
  122. if (versionBuild > 89) {
  123. versionName "${versionMajor}.${versionMinor}.${versionPatch}"
  124. } else if (versionBuild > 50) {
  125. versionName "${versionMajor}.${versionMinor}.${versionPatch} RC" + (versionBuild - 50)
  126. } else {
  127. versionName "${versionMajor}.${versionMinor}.${versionPatch} Alpha" + (versionBuild + 1)
  128. }
  129. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  130. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  131. flavorDimensions "default"
  132. buildTypes {
  133. debug {
  134. testCoverageEnabled (project.hasProperty('coverage'))
  135. }
  136. }
  137. productFlavors {
  138. // used for f-droid
  139. generic {
  140. applicationId 'com.nextcloud.client'
  141. dimension "default"
  142. }
  143. gplay {
  144. applicationId 'com.nextcloud.client'
  145. dimension "default"
  146. }
  147. versionDev {
  148. applicationId "com.nextcloud.android.beta"
  149. dimension "default"
  150. versionCode 20200129
  151. versionName "20200129"
  152. }
  153. qa {
  154. applicationId "com.nextcloud.android.qa"
  155. dimension "default"
  156. versionCode 1
  157. versionName "1"
  158. }
  159. }
  160. testOptions {
  161. unitTests.returnDefaultValues = true
  162. animationsDisabled true
  163. minSdkVersion testMinSdk
  164. }
  165. }
  166. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  167. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  168. dexOptions {
  169. // Skip pre-dexing when running on Travis CI or when disabled via -D pre-dex=false.
  170. preDexLibraries = preDexEnabled && !travisBuild
  171. }
  172. packagingOptions {
  173. exclude 'META-INF/LICENSE.txt'
  174. exclude 'META-INF/LICENSE'
  175. }
  176. tasks.register("checkstyle", Checkstyle) {
  177. configFile = file("${rootProject.projectDir}/checkstyle.xml")
  178. configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
  179. source 'src'
  180. include '**/*.java'
  181. exclude '**/gen/**'
  182. classpath = files()
  183. }
  184. tasks.register("pmd", Pmd) {
  185. ruleSetFiles = files("${project.rootDir}/ruleset.xml")
  186. ignoreFailures = true // should continue checking
  187. ruleSets = []
  188. source 'src'
  189. include '**/*.java'
  190. exclude '**/gen/**'
  191. reports {
  192. xml.enabled = false
  193. html.enabled = true
  194. xml {
  195. destination = file("$project.buildDir/reports/pmd/pmd.xml")
  196. }
  197. html {
  198. destination = file("$project.buildDir/reports/pmd/pmd.html")
  199. }
  200. }
  201. }
  202. android.applicationVariants.all { variant ->
  203. String variantName = variant.name
  204. String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1)
  205. tasks.register("spotbugs${capVariantName}Report", SpotBugsTask) {
  206. ignoreFailures = true // should continue checking
  207. effort = "max"
  208. reportLevel = "medium"
  209. classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/classes/")
  210. excludeFilter = file("${project.rootDir}/spotbugs-filter.xml")
  211. reports {
  212. xml.enabled = false
  213. html {
  214. enabled = true
  215. destination = file("$project.buildDir/reports/spotbugs/spotbugs.html")
  216. }
  217. }
  218. }
  219. }
  220. check.dependsOn 'checkstyle', 'spotbugsGplayDebugReport', 'pmd', 'lint', 'ktlint', 'detekt'
  221. compileOptions {
  222. sourceCompatibility JavaVersion.VERSION_1_8
  223. targetCompatibility JavaVersion.VERSION_1_8
  224. }
  225. buildFeatures {
  226. dataBinding true
  227. viewBinding true
  228. }
  229. }
  230. dependencies {
  231. // dependencies for app building
  232. implementation 'androidx.multidex:multidex:2.0.1'
  233. // implementation project('nextcloud-android-library')
  234. genericImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  235. gplayImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  236. versionDevImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  237. qaImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  238. kapt 'javax.xml.bind:jaxb-api:2.3.1'
  239. kapt 'org.glassfish.jaxb:jaxb-core:2.3.0.1'
  240. kapt 'org.glassfish.jaxb:jaxb-runtime:2.3.3'
  241. annotationProcessor 'javax.xml.bind:jaxb-api:2.3.1'
  242. annotationProcessor 'org.glassfish.jaxb:jaxb-core:2.3.0.1'
  243. annotationProcessor 'org.glassfish.jaxb:jaxb-runtime:2.3.3'
  244. 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
  245. implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  246. implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.1' // remove after entire switch to lib v2
  247. implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
  248. implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  249. implementation 'com.google.android.material:material:1.2.1'
  250. implementation 'com.jakewharton:disklrucache:2.0.2'
  251. implementation 'androidx.appcompat:appcompat:1.2.0-rc01'
  252. implementation 'androidx.cardview:cardview:1.0.0'
  253. implementation 'androidx.exifinterface:exifinterface:1.3.1'
  254. implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
  255. implementation "androidx.work:work-runtime:2.4.0"
  256. implementation "androidx.work:work-runtime-ktx:2.4.0"
  257. implementation "androidx.fragment:fragment:1.2.5"
  258. implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
  259. compileOnly 'com.google.code.findbugs:annotations:2.0.1'
  260. implementation 'commons-io:commons-io:2.8.0'
  261. implementation "com.jakewharton:butterknife:$butterknifeVersion"
  262. kapt "com.jakewharton:butterknife-compiler:$butterknifeVersion"
  263. implementation 'org.greenrobot:eventbus:3.2.0'
  264. implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.2'
  265. implementation 'org.lukhnos:nnio:0.2'
  266. implementation 'org.bouncycastle:bcpkix-jdk15on:1.65'
  267. implementation 'com.google.code.gson:gson:2.8.6'
  268. implementation 'com.afollestad:sectioned-recyclerview:0.5.0'
  269. implementation 'com.github.chrisbanes:PhotoView:2.3.0'
  270. implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.21'
  271. implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.2' // 'com.github.blikoon:QRCodeScanner:0.1.2'
  272. implementation 'com.google.android:flexbox:2.0.1'
  273. implementation 'org.parceler:parceler-api:1.1.13'
  274. kapt 'org.parceler:parceler:1.1.13'
  275. implementation('com.github.bumptech.glide:glide:3.8.0') {
  276. exclude group: "com.android.support"
  277. }
  278. implementation 'com.caverock:androidsvg:1.4'
  279. implementation 'androidx.annotation:annotation:1.1.0'
  280. implementation 'com.google.code.gson:gson:2.8.6'
  281. implementation 'com.vanniktech:emoji-google:0.7.0'
  282. implementation 'com.github.cotechde.hwsecurity:hwsecurity-fido:4.1.0'
  283. implementation 'com.github.cotechde.hwsecurity:hwsecurity-fido2:4.1.0'
  284. spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.11.0'
  285. spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
  286. implementation "com.google.dagger:dagger:$daggerVersion"
  287. implementation "com.google.dagger:dagger-android:$daggerVersion"
  288. implementation "com.google.dagger:dagger-android-support:$daggerVersion"
  289. kapt "com.google.dagger:dagger-compiler:$daggerVersion"
  290. kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
  291. ktlint "com.pinterest:ktlint:0.39.0"
  292. implementation 'org.conscrypt:conscrypt-android:2.5.1'
  293. // Shimmer animation
  294. implementation 'com.elyeproj.libraries:loaderviewlibrary:2.0.0'
  295. // dependencies for markdown rendering
  296. implementation "io.noties.markwon:core:$markwonVersion"
  297. implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
  298. implementation "io.noties.markwon:ext-tables:$markwonVersion"
  299. implementation "io.noties.markwon:ext-tasklist:$markwonVersion"
  300. implementation "io.noties.markwon:html:$markwonVersion"
  301. implementation "io.noties.markwon:syntax-highlight:$markwonVersion"
  302. implementation "io.noties:prism4j:$prismVersion"
  303. kapt "io.noties:prism4j-bundler:$prismVersion"
  304. // dependencies for local unit tests
  305. testImplementation 'junit:junit:4.13.1'
  306. testImplementation "org.mockito:mockito-core:$mockitoVersion"
  307. testImplementation 'androidx.test:core:1.3.0'
  308. testImplementation "org.powermock:powermock-core:$powermockVersion"
  309. testImplementation "org.powermock:powermock-module-junit4:$powermockVersion"
  310. testImplementation "org.powermock:powermock-api-mockito2:$powermockVersion"
  311. testImplementation 'org.json:json:20201115'
  312. testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  313. testImplementation 'androidx.arch.core:core-testing:2.1.0'
  314. testImplementation "io.mockk:mockk:$mockkVersion"
  315. testImplementation "io.mockk:mockk-android:$mockkVersion"
  316. // dependencies for instrumented tests
  317. // JUnit4 Rules
  318. androidTestImplementation 'androidx.test.ext:junit:1.1.2'
  319. androidTestImplementation 'androidx.test:rules:1.3.0'
  320. // Android JUnit Runner
  321. androidTestImplementation 'androidx.test:runner:1.3.0'
  322. androidTestUtil 'androidx.test:orchestrator:1.3.0'
  323. // Espresso core
  324. androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
  325. androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
  326. androidTestImplementation "androidx.test.espresso:espresso-web:$espressoVersion"
  327. // Mocking support
  328. androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5' // required to allow mocking on API 27 and older
  329. androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  330. androidTestImplementation "org.mockito:mockito-core:$mockitoVersion"
  331. androidTestImplementation("org.mockito:mockito-android:$mockitoVersion") {
  332. exclude group: "net.bytebuddy", module: "byte-buddy-android"
  333. }
  334. androidTestImplementation "net.bytebuddy:byte-buddy:$byteBuddyVersion"
  335. androidTestImplementation "net.bytebuddy:byte-buddy-android:$byteBuddyVersion"
  336. androidTestImplementation "io.mockk:mockk-android:1.10.0"
  337. androidTestImplementation 'androidx.arch.core:core-testing:2.0.1'
  338. // UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
  339. // androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
  340. // fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
  341. //androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
  342. androidTestImplementation 'tools.fastlane:screengrab:2.0.0'
  343. implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
  344. androidTestImplementation('com.android.support.test.espresso:espresso-intents:3.0.2')
  345. // jacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
  346. // jacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  347. // androidJacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  348. // androidJacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
  349. // androidJacocoAnt "org.jacoco:org.jacoco.core:${jacocoVersion}"
  350. // androidJacocoAnt "org.jacoco:org.jacoco.report:${jacocoVersion}"
  351. // androidJacocoAnt "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  352. implementation "com.github.stateless4j:stateless4j:2.6.0"
  353. }
  354. spotbugs {
  355. toolVersion = '3.1.12'
  356. }
  357. configurations.all {
  358. resolutionStrategy{
  359. cacheChangingModulesFor 0, 'seconds'
  360. force 'org.objenesis:objenesis:2.6'
  361. }
  362. }
  363. tasks.withType(Test) {
  364. // increased logging for tests
  365. testLogging {
  366. events "passed", "skipped", "failed"
  367. }
  368. }
  369. android.applicationVariants.all { variant ->
  370. variant.outputs.all { output ->
  371. outputFileName = "${output.baseName}-${variant.versionCode}.apk"
  372. }
  373. }
  374. tasks.register("combinedTestReport", JacocoReport) {
  375. reports {
  376. xml.enabled true
  377. html.enabled true
  378. csv.enabled false
  379. }
  380. additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
  381. sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
  382. classDirectories.setFrom files(subprojects.sourceSets.main.output)
  383. executionData.setFrom project.fileTree(dir: project.buildDir, includes: [
  384. 'jacoco/testGplayDebugUnitTest.exec', 'outputs/code-coverage/connected/flavors/GPLAY/*coverage.ec'
  385. ])
  386. }
  387. task ktlint(type: JavaExec, group: "verification") {
  388. description = "Check Kotlin code style."
  389. main = "com.pinterest.ktlint.Main"
  390. classpath = configurations.ktlint
  391. args "--reporter=plain", "--reporter=plain,output=${buildDir}/ktlint.txt,src/**/*.kt"
  392. }
  393. task ktlintFormat(type: JavaExec, group: "formatting") {
  394. description = "Fix Kotlin code style deviations."
  395. main = "com.pinterest.ktlint.Main"
  396. classpath = configurations.ktlint
  397. args "-F", "src/**/*.kt"
  398. }
  399. detekt {
  400. reports {
  401. xml {
  402. enabled = false
  403. }
  404. }
  405. config = files("detekt.yml")
  406. input = files("src/")
  407. }