build.gradle 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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 = 12
  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. }
  108. dexOptions {
  109. javaMaxHeapSize "4g"
  110. }
  111. compileSdkVersion 29
  112. defaultConfig {
  113. minSdkVersion 17
  114. targetSdkVersion 29
  115. // arguments to be passed to functional tests
  116. testInstrumentationRunner "com.nextcloud.client.ScreenshotTestRunner"
  117. testInstrumentationRunnerArgument "TEST_SERVER_URL", "${NC_TEST_SERVER_BASEURL}"
  118. testInstrumentationRunnerArgument "TEST_SERVER_USERNAME", "${NC_TEST_SERVER_USERNAME}"
  119. testInstrumentationRunnerArgument "TEST_SERVER_PASSWORD", "${NC_TEST_SERVER_PASSWORD}"
  120. testInstrumentationRunnerArguments disableAnalytics: 'true'
  121. multiDexEnabled true
  122. versionCode versionMajor * 10000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
  123. if (versionBuild > 89) {
  124. versionName "${versionMajor}.${versionMinor}.${versionPatch}"
  125. } else if (versionBuild > 50) {
  126. versionName "${versionMajor}.${versionMinor}.${versionPatch} RC" + (versionBuild - 50)
  127. } else {
  128. versionName "${versionMajor}.${versionMinor}.${versionPatch} Alpha" + (versionBuild + 1)
  129. }
  130. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  131. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  132. flavorDimensions "default"
  133. buildTypes {
  134. debug {
  135. testCoverageEnabled (project.hasProperty('coverage'))
  136. }
  137. }
  138. productFlavors {
  139. // used for f-droid
  140. generic {
  141. applicationId 'com.nextcloud.client'
  142. dimension "default"
  143. }
  144. gplay {
  145. applicationId 'com.nextcloud.client'
  146. dimension "default"
  147. }
  148. versionDev {
  149. applicationId "com.nextcloud.android.beta"
  150. dimension "default"
  151. versionCode 20200129
  152. versionName "20200129"
  153. }
  154. qa {
  155. applicationId "com.nextcloud.android.qa"
  156. dimension "default"
  157. versionCode 1
  158. versionName "1"
  159. }
  160. }
  161. testOptions {
  162. unitTests.returnDefaultValues = true
  163. // comment out if you run androidTests in Android Studio experiencing test runner crashes
  164. execution 'ANDROIDX_TEST_ORCHESTRATOR'
  165. animationsDisabled true
  166. }
  167. }
  168. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  169. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  170. dexOptions {
  171. // Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false.
  172. preDexLibraries = preDexEnabled && !travisBuild
  173. }
  174. packagingOptions {
  175. exclude 'META-INF/LICENSE.txt'
  176. exclude 'META-INF/LICENSE'
  177. }
  178. tasks.register("checkstyle", Checkstyle) {
  179. configFile = file("${rootProject.projectDir}/checkstyle.xml")
  180. configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
  181. source 'src'
  182. include '**/*.java'
  183. exclude '**/gen/**'
  184. classpath = files()
  185. }
  186. tasks.register("pmd", Pmd) {
  187. ruleSetFiles = files("${project.rootDir}/ruleset.xml")
  188. ignoreFailures = true // should continue checking
  189. ruleSets = []
  190. source 'src'
  191. include '**/*.java'
  192. exclude '**/gen/**'
  193. reports {
  194. xml.enabled = false
  195. html.enabled = true
  196. xml {
  197. destination = file("$project.buildDir/reports/pmd/pmd.xml")
  198. }
  199. html {
  200. destination = file("$project.buildDir/reports/pmd/pmd.html")
  201. }
  202. }
  203. }
  204. android.applicationVariants.all { variant ->
  205. String variantName = variant.name
  206. String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1)
  207. tasks.register("spotbugs${capVariantName}", SpotBugsTask) {
  208. ignoreFailures = true // should continue checking
  209. effort = "max"
  210. reportLevel = "medium"
  211. classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/classes/")
  212. excludeFilter = file("${project.rootDir}/spotbugs-filter.xml")
  213. pluginClasspath = project.configurations.spotbugsPlugins
  214. source = fileTree('src/main/java')
  215. classpath = files()
  216. include '**/*.java'
  217. exclude '**/gen/**'
  218. reports {
  219. xml.enabled = false
  220. html.enabled = true
  221. html {
  222. destination = file("$project.buildDir/reports/spotbugs/spotbugs.html")
  223. }
  224. }
  225. }
  226. }
  227. check.dependsOn 'checkstyle', 'spotbugsGplayDebug', 'pmd', 'lint', 'ktlint', 'detekt'
  228. compileOptions {
  229. sourceCompatibility JavaVersion.VERSION_1_8
  230. targetCompatibility JavaVersion.VERSION_1_8
  231. }
  232. dataBinding {
  233. enabled true
  234. }
  235. viewBinding {
  236. enabled true
  237. }
  238. }
  239. dependencies {
  240. // dependencies for app building
  241. implementation 'androidx.multidex:multidex:2.0.1'
  242. // implementation project('nextcloud-android-library')
  243. genericImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  244. gplayImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  245. versionDevImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  246. qaImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  247. 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
  248. implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  249. implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.1' // remove after entire switch to lib v2
  250. implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  251. implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  252. implementation 'com.google.android.material:material:1.1.0'
  253. implementation 'com.jakewharton:disklrucache:2.0.2'
  254. implementation 'androidx.appcompat:appcompat:1.2.0-beta01'
  255. implementation 'androidx.cardview:cardview:1.0.0'
  256. implementation 'androidx.exifinterface:exifinterface:1.2.0'
  257. implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
  258. implementation "androidx.work:work-runtime:2.3.4"
  259. implementation "androidx.work:work-runtime-ktx:2.3.4"
  260. implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
  261. compileOnly 'com.google.code.findbugs:annotations:2.0.1'
  262. implementation 'commons-io:commons-io:2.6'
  263. implementation 'com.github.tobiaskaminsky:android-job:v1.2.6.1' // 'com.github.evernote:android-job:v1.2.5'
  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.19'
  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. // dependencies for markdown rendering
  295. implementation "io.noties.markwon:core:$markwonVersion"
  296. implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
  297. implementation "io.noties.markwon:ext-tables:$markwonVersion"
  298. implementation "io.noties.markwon:ext-tasklist:$markwonVersion"
  299. implementation "io.noties.markwon:html:$markwonVersion"
  300. implementation "io.noties.markwon:syntax-highlight:$markwonVersion"
  301. implementation "io.noties:prism4j:$prismVersion"
  302. kapt "io.noties:prism4j-bundler:$prismVersion"
  303. // dependencies for local unit tests
  304. testImplementation 'junit:junit:4.13'
  305. testImplementation 'org.mockito:mockito-core:3.3.3'
  306. testImplementation 'androidx.test:core:1.2.0'
  307. testImplementation 'org.powermock:powermock-core:2.0.7'
  308. testImplementation 'org.powermock:powermock-module-junit4:2.0.7'
  309. testImplementation 'org.powermock:powermock-api-mockito2:2.0.7'
  310. testImplementation 'org.json:json:20190722'
  311. testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  312. testImplementation "androidx.arch.core:core-testing:2.1.0"
  313. // dependencies for instrumented tests
  314. // JUnit4 Rules
  315. androidTestImplementation 'androidx.test.ext:junit:1.1.1'
  316. androidTestImplementation 'androidx.test:rules:1.2.0'
  317. // Android JUnit Runner
  318. androidTestImplementation 'androidx.test:runner:1.2.0'
  319. androidTestUtil 'androidx.test:orchestrator:1.2.0'
  320. // Espresso core
  321. androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  322. androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
  323. androidTestImplementation 'org.mockito:mockito-core:3.3.1'
  324. // UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
  325. // androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
  326. // fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
  327. //androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
  328. androidTestImplementation 'tools.fastlane:screengrab:2.0.0'
  329. implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
  330. androidTestImplementation('com.android.support.test.espresso:espresso-intents:3.0.2')
  331. // jacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
  332. // jacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  333. // androidJacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  334. // androidJacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
  335. // androidJacocoAnt "org.jacoco:org.jacoco.core:${jacocoVersion}"
  336. // androidJacocoAnt "org.jacoco:org.jacoco.report:${jacocoVersion}"
  337. // androidJacocoAnt "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  338. implementation "com.github.stateless4j:stateless4j:2.6.0"
  339. androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  340. androidTestImplementation "org.mockito:mockito-android:3.3.3"
  341. }
  342. configurations.all {
  343. resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
  344. }
  345. tasks.withType(Test) {
  346. // increased logging for tests
  347. testLogging {
  348. events "passed", "skipped", "failed"
  349. }
  350. }
  351. android.applicationVariants.all { variant ->
  352. variant.outputs.all { output ->
  353. outputFileName = "${output.baseName}-${variant.versionCode}.apk"
  354. }
  355. }
  356. tasks.register("combinedTestReport", JacocoReport) {
  357. reports {
  358. xml.enabled = true
  359. html.enabled = true
  360. }
  361. def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
  362. def debugTree = fileTree(dir: "$project.buildDir/intermediates/classes/gplay/debug", excludes: fileFilter)
  363. def mainSrc = "$project.projectDir/src/main/java"
  364. sourceDirectories = files([mainSrc])
  365. classDirectories = files([debugTree])
  366. executionData = fileTree(dir: project.buildDir, includes: [
  367. 'jacoco/testGplayDebugUnitTest.exec', 'outputs/code-coverage/connected/flavors/GPLAY/*coverage.ec'
  368. ])
  369. }
  370. task ktlint(type: JavaExec, group: "verification") {
  371. description = "Check Kotlin code style."
  372. main = "com.pinterest.ktlint.Main"
  373. classpath = configurations.ktlint
  374. args "--reporter=plain", "--reporter=plain,output=${buildDir}/ktlint.txt,src/**/*.kt"
  375. }
  376. task ktlintFormat(type: JavaExec, group: "formatting") {
  377. description = "Fix Kotlin code style deviations."
  378. main = "com.pinterest.ktlint.Main"
  379. classpath = configurations.ktlint
  380. args "-F", "src/**/*.kt"
  381. }
  382. detekt {
  383. reports {
  384. xml {
  385. enabled = false
  386. }
  387. }
  388. config = files("detekt.yml")
  389. input = files("src/")
  390. }