build.gradle 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. buildscript {
  8. ext.kotlin_version = '1.3.72'
  9. repositories {
  10. google()
  11. jcenter()
  12. maven {
  13. url 'https://oss.sonatype.org/content/repositories/snapshots/'
  14. }
  15. maven {
  16. url 'https://plugins.gradle.org/m2/'
  17. }
  18. mavenCentral()
  19. }
  20. dependencies {
  21. classpath 'com.android.tools.build:gradle:4.0.0'
  22. classpath('com.hiya:jacoco-android:0.2')
  23. classpath 'gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.3.0'
  24. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  25. classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.9.1"
  26. classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  27. classpath 'com.karumi:shot:4.3.0'
  28. }
  29. }
  30. apply plugin: 'com.android.application'
  31. apply plugin: 'kotlin-android'
  32. apply plugin: 'kotlin-android-extensions'
  33. apply plugin: 'kotlin-kapt'
  34. apply plugin: 'checkstyle'
  35. apply plugin: 'pmd'
  36. apply plugin: 'com.hiya.jacoco-android'
  37. apply plugin: 'com.github.spotbugs'
  38. apply plugin: 'io.gitlab.arturbosch.detekt'
  39. apply plugin: 'shot'
  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.27"
  54. markwonVersion = "4.4.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 = 13
  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.contains("ExecuteScreenshot") || 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. checkGeneratedSources = true
  91. abortOnError false
  92. htmlReport true
  93. htmlOutput file("$project.buildDir/reports/lint/lint.html")
  94. disable 'MissingTranslation',
  95. 'GradleDependency',
  96. 'VectorPath',
  97. 'IconMissingDensityFolder',
  98. 'IconDensities',
  99. 'GoogleAppIndexingWarning',
  100. 'MissingDefaultResource',
  101. 'InvalidPeriodicWorkRequestInterval' // crashes due to a bug in lint itself
  102. }
  103. dexOptions {
  104. javaMaxHeapSize "4g"
  105. }
  106. compileSdkVersion 29
  107. defaultConfig {
  108. minSdkVersion 18
  109. targetSdkVersion 29
  110. // arguments to be passed to functional tests
  111. testInstrumentationRunner "com.nextcloud.client.ScreenshotTestRunner"
  112. testInstrumentationRunnerArgument "TEST_SERVER_URL", "${NC_TEST_SERVER_BASEURL}"
  113. testInstrumentationRunnerArgument "TEST_SERVER_USERNAME", "${NC_TEST_SERVER_USERNAME}"
  114. testInstrumentationRunnerArgument "TEST_SERVER_PASSWORD", "${NC_TEST_SERVER_PASSWORD}"
  115. testInstrumentationRunnerArguments disableAnalytics: 'true'
  116. multiDexEnabled true
  117. versionCode versionMajor * 10000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
  118. if (versionBuild > 89) {
  119. versionName "${versionMajor}.${versionMinor}.${versionPatch}"
  120. } else if (versionBuild > 50) {
  121. versionName "${versionMajor}.${versionMinor}.${versionPatch} RC" + (versionBuild - 50)
  122. } else {
  123. versionName "${versionMajor}.${versionMinor}.${versionPatch} Alpha" + (versionBuild + 1)
  124. }
  125. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  126. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  127. flavorDimensions "default"
  128. buildTypes {
  129. debug {
  130. testCoverageEnabled (project.hasProperty('coverage'))
  131. }
  132. }
  133. productFlavors {
  134. // used for f-droid
  135. generic {
  136. applicationId 'com.nextcloud.client'
  137. dimension "default"
  138. }
  139. gplay {
  140. applicationId 'com.nextcloud.client'
  141. dimension "default"
  142. }
  143. versionDev {
  144. applicationId "com.nextcloud.android.beta"
  145. dimension "default"
  146. versionCode 20200129
  147. versionName "20200129"
  148. }
  149. qa {
  150. applicationId "com.nextcloud.android.qa"
  151. dimension "default"
  152. versionCode 1
  153. versionName "1"
  154. }
  155. }
  156. testOptions {
  157. unitTests.returnDefaultValues = true
  158. animationsDisabled true
  159. }
  160. }
  161. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  162. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  163. dexOptions {
  164. // Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false.
  165. preDexLibraries = preDexEnabled && !travisBuild
  166. }
  167. packagingOptions {
  168. exclude 'META-INF/LICENSE.txt'
  169. exclude 'META-INF/LICENSE'
  170. }
  171. tasks.register("checkstyle", Checkstyle) {
  172. configFile = file("${rootProject.projectDir}/checkstyle.xml")
  173. configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
  174. source 'src'
  175. include '**/*.java'
  176. exclude '**/gen/**'
  177. classpath = files()
  178. }
  179. tasks.register("pmd", Pmd) {
  180. ruleSetFiles = files("${project.rootDir}/ruleset.xml")
  181. ignoreFailures = true // should continue checking
  182. ruleSets = []
  183. source 'src'
  184. include '**/*.java'
  185. exclude '**/gen/**'
  186. reports {
  187. xml.enabled = false
  188. html.enabled = true
  189. xml {
  190. destination = file("$project.buildDir/reports/pmd/pmd.xml")
  191. }
  192. html {
  193. destination = file("$project.buildDir/reports/pmd/pmd.html")
  194. }
  195. }
  196. }
  197. android.applicationVariants.all { variant ->
  198. String variantName = variant.name
  199. String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1)
  200. tasks.register("spotbugs${capVariantName}Report", com.github.spotbugs.snom.SpotBugsTask) {
  201. ignoreFailures = true // should continue checking
  202. effort = "max"
  203. reportLevel = "medium"
  204. classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/classes/")
  205. excludeFilter = file("${project.rootDir}/spotbugs-filter.xml")
  206. reports {
  207. xml.enabled = false
  208. html.enabled = true
  209. html {
  210. destination = file("$project.buildDir/reports/spotbugs/spotbugs.html")
  211. }
  212. }
  213. }
  214. }
  215. check.dependsOn 'checkstyle', 'spotbugsGplayDebugReport', 'pmd', 'lint', 'ktlint', 'detekt'
  216. compileOptions {
  217. sourceCompatibility JavaVersion.VERSION_1_8
  218. targetCompatibility JavaVersion.VERSION_1_8
  219. }
  220. dataBinding {
  221. enabled true
  222. }
  223. viewBinding {
  224. enabled true
  225. }
  226. }
  227. dependencies {
  228. // dependencies for app building
  229. implementation 'androidx.multidex:multidex:2.0.1'
  230. // implementation project('nextcloud-android-library')
  231. genericImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  232. gplayImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  233. versionDevImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  234. qaImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  235. kapt 'javax.xml.bind:jaxb-api:2.3.1'
  236. kapt 'org.glassfish.jaxb:jaxb-core:2.3.0.1'
  237. kapt 'org.glassfish.jaxb:jaxb-runtime:2.3.3'
  238. annotationProcessor 'javax.xml.bind:jaxb-api:2.3.1'
  239. annotationProcessor 'org.glassfish.jaxb:jaxb-core:2.3.0.1'
  240. annotationProcessor 'org.glassfish.jaxb:jaxb-runtime:2.3.3'
  241. 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
  242. implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  243. implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.1' // remove after entire switch to lib v2
  244. implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  245. implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  246. implementation 'com.google.android.material:material:1.1.0'
  247. implementation 'com.jakewharton:disklrucache:2.0.2'
  248. implementation 'androidx.appcompat:appcompat:1.2.0-rc01'
  249. implementation 'androidx.cardview:cardview:1.0.0'
  250. implementation 'androidx.exifinterface:exifinterface:1.2.0'
  251. implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
  252. implementation "androidx.work:work-runtime:2.3.4"
  253. implementation "androidx.work:work-runtime-ktx:2.3.4"
  254. implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
  255. compileOnly 'com.google.code.findbugs:annotations:2.0.1'
  256. implementation 'commons-io:commons-io:2.7'
  257. implementation 'com.jakewharton:butterknife:10.2.1'
  258. kapt 'com.jakewharton:butterknife-compiler:10.2.1'
  259. implementation 'org.greenrobot:eventbus:3.2.0'
  260. implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.6'
  261. implementation 'org.lukhnos:nnio:0.2'
  262. implementation 'org.bouncycastle:bcpkix-jdk15on:1.65'
  263. implementation 'com.google.code.gson:gson:2.8.6'
  264. implementation 'com.afollestad:sectioned-recyclerview:0.5.0'
  265. implementation 'com.github.chrisbanes:PhotoView:2.3.0'
  266. implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.20'
  267. implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.2' // 'com.github.blikoon:QRCodeScanner:0.1.2'
  268. implementation 'com.google.android:flexbox:2.0.1'
  269. implementation 'org.parceler:parceler-api:1.1.13'
  270. kapt 'org.parceler:parceler:1.1.13'
  271. implementation('com.github.bumptech.glide:glide:3.8.0') {
  272. exclude group: "com.android.support"
  273. }
  274. implementation 'com.caverock:androidsvg:1.4'
  275. implementation 'androidx.annotation:annotation:1.1.0'
  276. implementation 'com.google.code.gson:gson:2.8.6'
  277. implementation 'com.github.cotechde.hwsecurity:hwsecurity-fido:2.5.1'
  278. spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.10.1'
  279. spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
  280. implementation "com.google.dagger:dagger:$daggerVersion"
  281. implementation "com.google.dagger:dagger-android:$daggerVersion"
  282. implementation "com.google.dagger:dagger-android-support:$daggerVersion"
  283. kapt "com.google.dagger:dagger-compiler:$daggerVersion"
  284. kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
  285. ktlint "com.pinterest:ktlint:0.37.2"
  286. implementation 'org.conscrypt:conscrypt-android:2.4.0'
  287. // Shimmer animation
  288. implementation 'com.elyeproj.libraries:loaderviewlibrary:2.0.0'
  289. // dependencies for markdown rendering
  290. implementation "io.noties.markwon:core:$markwonVersion"
  291. implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
  292. implementation "io.noties.markwon:ext-tables:$markwonVersion"
  293. implementation "io.noties.markwon:ext-tasklist:$markwonVersion"
  294. implementation "io.noties.markwon:html:$markwonVersion"
  295. implementation "io.noties.markwon:syntax-highlight:$markwonVersion"
  296. implementation "io.noties:prism4j:$prismVersion"
  297. kapt "io.noties:prism4j-bundler:$prismVersion"
  298. // dependencies for local unit tests
  299. testImplementation 'junit:junit:4.13'
  300. testImplementation 'org.mockito:mockito-core:3.3.3'
  301. testImplementation 'androidx.test:core:1.2.0'
  302. testImplementation 'org.powermock:powermock-core:2.0.7'
  303. testImplementation 'org.powermock:powermock-module-junit4:2.0.7'
  304. testImplementation 'org.powermock:powermock-api-mockito2:2.0.7'
  305. testImplementation 'org.json:json:20200518'
  306. testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  307. testImplementation "androidx.arch.core:core-testing:2.1.0"
  308. // dependencies for instrumented tests
  309. // JUnit4 Rules
  310. androidTestImplementation 'androidx.test.ext:junit:1.1.1'
  311. androidTestImplementation 'androidx.test:rules:1.2.0'
  312. // Android JUnit Runner
  313. androidTestImplementation 'androidx.test:runner:1.2.0'
  314. androidTestUtil 'androidx.test:orchestrator:1.2.0'
  315. // Espresso core
  316. androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  317. androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
  318. androidTestImplementation 'org.mockito:mockito-core:3.3.1'
  319. // UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
  320. // androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
  321. // fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
  322. //androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
  323. androidTestImplementation 'tools.fastlane:screengrab:2.0.0'
  324. implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
  325. androidTestImplementation('com.android.support.test.espresso:espresso-intents:3.0.2')
  326. // jacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
  327. // jacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  328. // androidJacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  329. // androidJacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
  330. // androidJacocoAnt "org.jacoco:org.jacoco.core:${jacocoVersion}"
  331. // androidJacocoAnt "org.jacoco:org.jacoco.report:${jacocoVersion}"
  332. // androidJacocoAnt "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  333. implementation "com.github.stateless4j:stateless4j:2.6.0"
  334. androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  335. androidTestImplementation "org.mockito:mockito-android:3.3.3"
  336. androidTestImplementation 'net.bytebuddy:byte-buddy:1.10.12'
  337. }
  338. configurations.all {
  339. resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
  340. }
  341. tasks.withType(Test) {
  342. // increased logging for tests
  343. testLogging {
  344. events "passed", "skipped", "failed"
  345. }
  346. }
  347. android.applicationVariants.all { variant ->
  348. variant.outputs.all { output ->
  349. outputFileName = "${output.baseName}-${variant.versionCode}.apk"
  350. }
  351. }
  352. tasks.register("combinedTestReport", JacocoReport) {
  353. reports {
  354. xml.enabled = true
  355. html.enabled = true
  356. }
  357. def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
  358. def debugTree = fileTree(dir: "$project.buildDir/intermediates/classes/gplay/debug", excludes: fileFilter)
  359. def mainSrc = "$project.projectDir/src/main/java"
  360. sourceDirectories = files([mainSrc])
  361. classDirectories = files([debugTree])
  362. executionData = fileTree(dir: project.buildDir, includes: [
  363. 'jacoco/testGplayDebugUnitTest.exec', 'outputs/code-coverage/connected/flavors/GPLAY/*coverage.ec'
  364. ])
  365. }
  366. task ktlint(type: JavaExec, group: "verification") {
  367. description = "Check Kotlin code style."
  368. main = "com.pinterest.ktlint.Main"
  369. classpath = configurations.ktlint
  370. args "--reporter=plain", "--reporter=plain,output=${buildDir}/ktlint.txt,src/**/*.kt"
  371. }
  372. task ktlintFormat(type: JavaExec, group: "formatting") {
  373. description = "Fix Kotlin code style deviations."
  374. main = "com.pinterest.ktlint.Main"
  375. classpath = configurations.ktlint
  376. args "-F", "src/**/*.kt"
  377. }
  378. detekt {
  379. reports {
  380. xml {
  381. enabled = false
  382. }
  383. }
  384. config = files("detekt.yml")
  385. input = files("src/")
  386. }