build.gradle 17 KB

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