build.gradle 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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.50'
  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.5.2'
  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.1.1"
  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: 'jacoco-android'
  38. apply plugin: "com.github.spotbugs"
  39. apply plugin: "io.gitlab.arturbosch.detekt"
  40. configurations {
  41. ktlint
  42. all {
  43. exclude group: 'com.google.firebase', module: 'firebase-core'
  44. exclude group: 'com.google.firebase', module: 'firebase-analytics'
  45. exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'
  46. exclude group: 'org.jetbrains', module: 'annotations-java5' // via prism4j, already using annotations explicitely
  47. // check for updates every build
  48. resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
  49. }
  50. }
  51. ext {
  52. jacocoVersion = "0.8.2"
  53. daggerVersion = "2.25.2"
  54. markwonVersion = "4.1.2"
  55. prismVersion = "2.0.0"
  56. androidLibraryVersion = "master-SNAPSHOT"
  57. travisBuild = System.getenv("TRAVIS") == "true"
  58. // allows for -Dpre-dex=false to be set
  59. preDexEnabled = "true".equals(System.getProperty("pre-dex", "true"))
  60. }
  61. repositories {
  62. google()
  63. jcenter()
  64. maven { url "https://jitpack.io" }
  65. maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
  66. flatDir {
  67. dirs 'libs'
  68. }
  69. }
  70. // semantic versioning for version code
  71. def versionMajor = 3
  72. def versionMinor = 10
  73. def versionPatch = 0
  74. def versionBuild = 0 // 0-50=Alpha / 51-98=RC / 90-99=stable
  75. for (TaskExecutionRequest tr : getGradle().getStartParameter().getTaskRequests()) {
  76. for (String arg : tr.args) {
  77. // any gplay, but only exact "build", as e.g. buildGeneric shall not apply gplay.grade
  78. if (arg.contains("Gplay") || arg.contains("lint") || arg == "build") {
  79. apply from: 'gplay.gradle'
  80. System.console().println("Applying gplay.gradle")
  81. break
  82. }
  83. }
  84. }
  85. spotbugs {
  86. toolVersion = '3.1.12'
  87. }
  88. android {
  89. lintOptions {
  90. abortOnError false
  91. htmlReport true
  92. htmlOutput file("$project.buildDir/reports/lint/lint.html")
  93. disable 'MissingTranslation', 'GradleDependency', 'VectorPath', 'IconMissingDensityFolder', 'IconDensities'
  94. }
  95. dexOptions {
  96. javaMaxHeapSize "4g"
  97. }
  98. compileSdkVersion 28
  99. defaultConfig {
  100. minSdkVersion 16
  101. targetSdkVersion 28
  102. // arguments to be passed to functional tests
  103. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  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. multiDexEnabled 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. productFlavors {
  125. // used for f-droid
  126. generic {
  127. applicationId 'com.nextcloud.client'
  128. dimension "default"
  129. }
  130. gplay {
  131. applicationId 'com.nextcloud.client'
  132. dimension "default"
  133. }
  134. versionDev {
  135. applicationId "com.nextcloud.android.beta"
  136. dimension "default"
  137. versionCode 20191108
  138. versionName "20191108"
  139. }
  140. qa {
  141. applicationId "com.nextcloud.android.qa"
  142. dimension "default"
  143. versionCode 1
  144. versionName "1"
  145. }
  146. }
  147. testOptions {
  148. unitTests.returnDefaultValues = true
  149. }
  150. }
  151. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  152. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  153. dexOptions {
  154. // Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false.
  155. preDexLibraries = preDexEnabled && !travisBuild
  156. }
  157. packagingOptions {
  158. exclude 'META-INF/LICENSE.txt'
  159. exclude 'META-INF/LICENSE'
  160. }
  161. tasks.register("checkstyle", Checkstyle) {
  162. configFile = file("${rootProject.projectDir}/checkstyle.xml")
  163. configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
  164. source 'src'
  165. include '**/*.java'
  166. exclude '**/gen/**'
  167. classpath = files()
  168. }
  169. tasks.register("pmd", Pmd) {
  170. ruleSetFiles = files("${project.rootDir}/ruleset.xml")
  171. ignoreFailures = true // should continue checking
  172. ruleSets = []
  173. source 'src'
  174. include '**/*.java'
  175. exclude '**/gen/**'
  176. reports {
  177. xml.enabled = false
  178. html.enabled = true
  179. xml {
  180. destination = file("$project.buildDir/reports/pmd/pmd.xml")
  181. }
  182. html {
  183. destination = file("$project.buildDir/reports/pmd/pmd.html")
  184. }
  185. }
  186. }
  187. android.applicationVariants.all { variant ->
  188. String variantName = variant.name
  189. String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1)
  190. tasks.register("spotbugs${capVariantName}", SpotBugsTask) {
  191. ignoreFailures = true // should continue checking
  192. effort = "max"
  193. reportLevel = "medium"
  194. classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/classes/")
  195. excludeFilter = file("${project.rootDir}/spotbugs-filter.xml")
  196. pluginClasspath = project.configurations.spotbugsPlugins
  197. source = fileTree('src/main/java')
  198. classpath = files()
  199. include '**/*.java'
  200. exclude '**/gen/**'
  201. reports {
  202. xml.enabled = false
  203. html.enabled = true
  204. html {
  205. destination = file("$project.buildDir/reports/spotbugs/spotbugs.html")
  206. }
  207. }
  208. }
  209. }
  210. check.dependsOn 'checkstyle', 'spotbugsGplayDebug', 'pmd', 'lint', 'ktlint', 'detekt'
  211. compileOptions {
  212. sourceCompatibility JavaVersion.VERSION_1_8
  213. targetCompatibility JavaVersion.VERSION_1_8
  214. }
  215. dataBinding {
  216. enabled true
  217. }
  218. }
  219. dependencies {
  220. // dependencies for app building
  221. implementation 'androidx.multidex:multidex:2.0.1'
  222. // implementation project('nextcloud-android-library')
  223. genericImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  224. gplayImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  225. versionDevImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  226. qaImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  227. implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  228. implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  229. implementation 'com.google.android.material:material:1.1.0-beta01'
  230. implementation 'com.jakewharton:disklrucache:2.0.2'
  231. implementation 'androidx.appcompat:appcompat:1.1.0'
  232. implementation 'androidx.cardview:cardview:1.0.0'
  233. implementation 'androidx.exifinterface:exifinterface:1.0.0'
  234. implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0"
  235. implementation "androidx.work:work-runtime:2.2.0"
  236. implementation "androidx.work:work-runtime-ktx:2.2.0"
  237. implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
  238. implementation 'com.google.code.findbugs:annotations:2.0.1'
  239. implementation 'commons-io:commons-io:2.6'
  240. implementation 'com.github.tobiaskaminsky:android-job:v1.2.6.1' // 'com.github.evernote:android-job:v1.2.5'
  241. implementation 'com.jakewharton:butterknife:10.2.0'
  242. kapt 'com.jakewharton:butterknife-compiler:10.2.0'
  243. implementation 'org.greenrobot:eventbus:3.1.1'
  244. implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'
  245. implementation 'org.lukhnos:nnio:0.2'
  246. implementation 'com.madgag.spongycastle:pkix:1.54.0.0'
  247. implementation 'com.google.code.gson:gson:2.8.6'
  248. implementation 'com.afollestad:sectioned-recyclerview:0.5.0'
  249. implementation 'com.github.chrisbanes:PhotoView:2.3.0'
  250. implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15'
  251. implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.2' // 'com.github.blikoon:QRCodeScanner:0.1.2'
  252. implementation 'com.google.android:flexbox:1.1.1'
  253. implementation 'org.parceler:parceler-api:1.1.12'
  254. kapt 'org.parceler:parceler:1.1.12'
  255. implementation('com.github.bumptech.glide:glide:3.8.0') {
  256. exclude group: "com.android.support"
  257. }
  258. implementation 'com.caverock:androidsvg:1.4'
  259. implementation 'androidx.annotation:annotation:1.1.0'
  260. implementation 'com.google.code.gson:gson:2.8.6'
  261. implementation 'org.jetbrains:annotations:18.0.0'
  262. implementation 'com.github.cotechde.hwsecurity:hwsecurity-fido:2.5.1'
  263. spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.10.1'
  264. spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
  265. implementation "com.google.dagger:dagger:$daggerVersion"
  266. implementation "com.google.dagger:dagger-android:$daggerVersion"
  267. implementation "com.google.dagger:dagger-android-support:$daggerVersion"
  268. kapt "com.google.dagger:dagger-compiler:$daggerVersion"
  269. kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
  270. compileOnly "org.projectlombok:lombok:1.18.10"
  271. annotationProcessor "org.projectlombok:lombok:1.18.10"
  272. ktlint "com.pinterest:ktlint:0.35.0"
  273. implementation 'org.conscrypt:conscrypt-android:2.2.1'
  274. // dependencies for markdown rendering
  275. implementation "io.noties.markwon:core:$markwonVersion"
  276. implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
  277. implementation "io.noties.markwon:ext-tables:$markwonVersion"
  278. implementation "io.noties.markwon:ext-tasklist:$markwonVersion"
  279. implementation "io.noties.markwon:html:$markwonVersion"
  280. implementation "io.noties.markwon:syntax-highlight:$markwonVersion"
  281. implementation "io.noties:prism4j:$prismVersion"
  282. kapt "io.noties:prism4j-bundler:$prismVersion"
  283. // dependencies for local unit tests
  284. testImplementation 'junit:junit:4.12'
  285. testImplementation 'org.mockito:mockito-core:3.1.0'
  286. testImplementation 'androidx.test:core:1.2.0'
  287. testImplementation 'org.powermock:powermock-core:2.0.4'
  288. testImplementation 'org.powermock:powermock-module-junit4:2.0.4'
  289. testImplementation 'org.powermock:powermock-api-mockito2:2.0.4'
  290. testImplementation 'org.json:json:20190722'
  291. testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  292. testImplementation "androidx.arch.core:core-testing:2.1.0"
  293. // dependencies for instrumented tests
  294. // JUnit4 Rules
  295. androidTestImplementation 'androidx.test.ext:junit:1.1.1'
  296. androidTestImplementation 'androidx.test:rules:1.2.0'
  297. // Android JUnit Runner
  298. androidTestImplementation 'androidx.test:runner:1.2.0'
  299. // Espresso core
  300. androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  301. androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
  302. androidTestImplementation 'org.mockito:mockito-core:3.1.0'
  303. // UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
  304. // androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
  305. // fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
  306. //androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
  307. androidTestImplementation 'tools.fastlane:screengrab:1.2.0'
  308. implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
  309. // jacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
  310. // jacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  311. // androidJacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  312. // androidJacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
  313. // androidJacocoAnt "org.jacoco:org.jacoco.core:${jacocoVersion}"
  314. // androidJacocoAnt "org.jacoco:org.jacoco.report:${jacocoVersion}"
  315. // androidJacocoAnt "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  316. implementation "com.github.stateless4j:stateless4j:2.6.0"
  317. }
  318. configurations.all {
  319. resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
  320. }
  321. tasks.withType(Test) {
  322. // increased logging for tests
  323. testLogging {
  324. events "passed", "skipped", "failed"
  325. }
  326. }
  327. android.applicationVariants.all { variant ->
  328. variant.outputs.all { output ->
  329. outputFileName = "${output.baseName}-${variant.versionCode}.apk"
  330. }
  331. }
  332. tasks.register("combinedTestReport", JacocoReport) {
  333. reports {
  334. xml.enabled = true
  335. html.enabled = true
  336. }
  337. def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
  338. def debugTree = fileTree(dir: "$project.buildDir/intermediates/classes/gplay/debug", excludes: fileFilter)
  339. def mainSrc = "$project.projectDir/src/main/java"
  340. sourceDirectories = files([mainSrc])
  341. classDirectories = files([debugTree])
  342. executionData = fileTree(dir: project.buildDir, includes: [
  343. 'jacoco/testGplayDebugUnitTest.exec', 'outputs/code-coverage/connected/flavors/GPLAY/*coverage.ec'
  344. ])
  345. }
  346. task ktlint(type: JavaExec, group: "verification") {
  347. description = "Check Kotlin code style."
  348. main = "com.pinterest.ktlint.Main"
  349. classpath = configurations.ktlint
  350. args "--reporter=plain", "--reporter=plain,output=${buildDir}/ktlint.txt,src/**/*.kt"
  351. }
  352. task ktlintFormat(type: JavaExec, group: "formatting") {
  353. description = "Fix Kotlin code style deviations."
  354. main = "com.pinterest.ktlint.Main"
  355. classpath = configurations.ktlint
  356. args "-F", "src/**/*.kt"
  357. }
  358. detekt {
  359. reports {
  360. xml {
  361. enabled = false
  362. }
  363. }
  364. config = files("detekt.yml")
  365. input = files("src/")
  366. }