build.gradle 16 KB

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