build.gradle 15 KB

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