build.gradle 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. import com.github.spotbugs.snom.SpotBugsTask
  2. import org.gradle.internal.jvm.Jvm
  3. buildscript {
  4. dependencies {
  5. classpath 'com.android.tools.build:gradle:7.1.3'
  6. classpath 'com.hiya:jacoco-android:0.2'
  7. classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.6'
  8. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  9. classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.20.0"
  10. classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  11. classpath 'com.karumi:shot:5.14.0'
  12. classpath "org.jacoco:org.jacoco.core:$jacoco_version"
  13. classpath "org.jacoco:org.jacoco.report:$jacoco_version"
  14. classpath "org.jacoco:org.jacoco.agent:$jacoco_version"
  15. classpath "org.jlleitschuh.gradle:ktlint-gradle:10.2.1"
  16. }
  17. }
  18. apply plugin: 'com.android.application'
  19. apply plugin: 'kotlin-android'
  20. apply plugin: 'kotlin-kapt'
  21. apply plugin: 'kotlin-parcelize'
  22. apply plugin: 'checkstyle'
  23. apply plugin: 'pmd'
  24. apply plugin: 'com.hiya.jacoco-android'
  25. apply plugin: 'com.github.spotbugs'
  26. apply plugin: 'io.gitlab.arturbosch.detekt'
  27. apply plugin: 'shot'
  28. apply plugin: "org.jlleitschuh.gradle.ktlint"
  29. println "Gradle uses Java ${Jvm.current()}"
  30. configurations {
  31. all {
  32. exclude group: 'org.jetbrains', module: 'annotations-java5' // via prism4j, already using annotations explicitly
  33. // check for updates every build
  34. resolutionStrategy {
  35. cacheChangingModulesFor 0, 'seconds'
  36. exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug"
  37. }
  38. }
  39. }
  40. configurations.configureEach {
  41. resolutionStrategy.eachDependency {
  42. if (requested.group == "org.checkerframework" && requested.name != "checker-compat-qual") {
  43. useVersion(checkerVersion)
  44. because("https://github.com/google/ExoPlayer/issues/10007")
  45. }
  46. }
  47. }
  48. repositories {
  49. google()
  50. maven { url "https://jitpack.io" }
  51. mavenCentral()
  52. maven {
  53. url 'https://plugins.gradle.org/m2/'
  54. }
  55. }
  56. // semantic versioning for version code
  57. def versionMajor = 3
  58. def versionMinor = 20
  59. def versionPatch = 0
  60. def versionBuild = 0 // 0-50=Alpha / 51-98=RC / 90-99=stable
  61. def ndkEnv = new HashMap<String, String>()
  62. file("$project.rootDir/ndk.env").readLines().each() {
  63. def (key, value) = it.tokenize('=')
  64. ndkEnv.put(key, value)
  65. }
  66. android {
  67. compileSdkVersion 31
  68. // install this NDK version and Cmake to produce smaller APKs. Build will still work if not installed
  69. ndkVersion "${ndkEnv.get("NDK_VERSION")}"
  70. defaultConfig {
  71. minSdkVersion 23
  72. targetSdkVersion 30
  73. buildConfigField 'boolean', 'CI', ciBuild.toString()
  74. // arguments to be passed to functional tests
  75. testInstrumentationRunner "com.nextcloud.client.ScreenshotTestRunner"
  76. testInstrumentationRunnerArgument "TEST_SERVER_URL", "${NC_TEST_SERVER_BASEURL}"
  77. testInstrumentationRunnerArgument "TEST_SERVER_USERNAME", "${NC_TEST_SERVER_USERNAME}"
  78. testInstrumentationRunnerArgument "TEST_SERVER_PASSWORD", "${NC_TEST_SERVER_PASSWORD}"
  79. testInstrumentationRunnerArguments disableAnalytics: 'true'
  80. multiDexEnabled true
  81. versionCode versionMajor * 10000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
  82. if (versionBuild > 89) {
  83. versionName "${versionMajor}.${versionMinor}.${versionPatch}"
  84. } else if (versionBuild > 50) {
  85. versionName "${versionMajor}.${versionMinor}.${versionPatch} RC" + (versionBuild - 50)
  86. } else {
  87. versionName "${versionMajor}.${versionMinor}.${versionPatch} Alpha" + (versionBuild + 1)
  88. }
  89. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  90. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  91. flavorDimensions "default"
  92. buildTypes {
  93. debug {
  94. testCoverageEnabled (project.hasProperty('coverage'))
  95. }
  96. }
  97. productFlavors {
  98. // used for f-droid
  99. generic {
  100. applicationId 'com.nextcloud.client'
  101. dimension "default"
  102. }
  103. gplay {
  104. applicationId 'com.nextcloud.client'
  105. dimension "default"
  106. }
  107. huawei {
  108. applicationId 'com.nextcloud.client'
  109. dimension "default"
  110. }
  111. versionDev {
  112. applicationId "com.nextcloud.android.beta"
  113. dimension "default"
  114. versionCode 20220322
  115. versionName "20220322"
  116. }
  117. qa {
  118. applicationId "com.nextcloud.android.qa"
  119. dimension "default"
  120. versionCode 1
  121. versionName "1"
  122. }
  123. }
  124. testOptions {
  125. unitTests.returnDefaultValues = true
  126. animationsDisabled true
  127. }
  128. }
  129. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  130. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  131. packagingOptions {
  132. resources {
  133. excludes += ['META-INF/LICENSE.txt', 'META-INF/LICENSE']
  134. }
  135. }
  136. tasks.register("checkstyle", Checkstyle) {
  137. configFile = file("${rootProject.projectDir}/checkstyle.xml")
  138. configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
  139. source 'src'
  140. include '**/*.java'
  141. exclude '**/gen/**'
  142. classpath = files()
  143. }
  144. tasks.register("pmd", Pmd) {
  145. ruleSetFiles = files("${project.rootDir}/ruleset.xml")
  146. ignoreFailures = true // should continue checking
  147. ruleSets = []
  148. source 'src'
  149. include '**/*.java'
  150. exclude '**/gen/**'
  151. reports {
  152. xml.enabled = false
  153. html.enabled = true
  154. xml {
  155. destination = file("$project.buildDir/reports/pmd/pmd.xml")
  156. }
  157. html {
  158. destination = file("$project.buildDir/reports/pmd/pmd.html")
  159. }
  160. }
  161. }
  162. check.dependsOn 'checkstyle', 'spotbugsGplayDebug', 'pmd', 'lint', 'ktlintCheck', 'detekt'
  163. buildFeatures {
  164. dataBinding true
  165. viewBinding true
  166. }
  167. kotlinOptions {
  168. jvmTarget = "1.8"
  169. }
  170. lint {
  171. abortOnError false
  172. checkGeneratedSources true
  173. disable 'MissingTranslation', 'GradleDependency', 'VectorPath', 'IconMissingDensityFolder', 'IconDensities', 'GoogleAppIndexingWarning', 'MissingDefaultResource', 'InvalidPeriodicWorkRequestInterval', 'StringFormatInvalid', 'MissingQuantity'
  174. htmlOutput file("$project.buildDir/reports/lint/lint.html")
  175. htmlReport true
  176. }
  177. }
  178. dependencies {
  179. // dependencies for app building
  180. implementation 'androidx.multidex:multidex:2.0.1'
  181. // implementation project('nextcloud-android-library')
  182. implementation ("com.github.nextcloud:android-library:$androidLibraryVersion") {
  183. exclude group: 'org.ogce', module: 'xpp3' // unused in Android and brings wrong Junit version
  184. }
  185. 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
  186. implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  187. implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.5' // remove after entire switch to lib v2
  188. implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
  189. implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  190. implementation 'com.google.android.material:material:1.5.0'
  191. implementation 'com.jakewharton:disklrucache:2.0.2'
  192. implementation 'androidx.appcompat:appcompat:1.4.1'
  193. implementation 'androidx.webkit:webkit:1.4.0'
  194. implementation 'androidx.cardview:cardview:1.0.0'
  195. implementation 'androidx.exifinterface:exifinterface:1.3.3'
  196. implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1"
  197. implementation "androidx.work:work-runtime:$workRuntime"
  198. implementation "androidx.work:work-runtime-ktx:$workRuntime"
  199. implementation "androidx.fragment:fragment-ktx:1.4.1"
  200. implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
  201. compileOnly 'com.google.code.findbugs:annotations:3.0.1u2'
  202. implementation 'commons-io:commons-io:2.11.0'
  203. implementation 'org.greenrobot:eventbus:3.3.1'
  204. implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3'
  205. implementation 'org.lukhnos:nnio:0.2'
  206. implementation 'org.bouncycastle:bcpkix-jdk15to18:1.70'
  207. implementation 'com.google.code.gson:gson:2.9.0'
  208. implementation 'com.afollestad:sectioned-recyclerview:0.5.0'
  209. implementation 'com.github.chrisbanes:PhotoView:2.3.0'
  210. implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.24'
  211. implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.4' // 'com.github.blikoon:QRCodeScanner:0.1.2'
  212. implementation 'com.google.android:flexbox:2.0.1'
  213. implementation('com.github.bumptech.glide:glide:3.8.0') {
  214. exclude group: "com.android.support"
  215. }
  216. implementation 'com.caverock:androidsvg:1.4'
  217. implementation 'androidx.annotation:annotation:1.3.0'
  218. implementation 'com.vanniktech:emoji-google:0.9.0'
  219. implementation "com.github.cotechde.hwsecurity:hwsecurity-fido:$fidoVersion"
  220. implementation "com.github.cotechde.hwsecurity:hwsecurity-fido2:$fidoVersion"
  221. // document scanner not available on FDroid (generic) due to OpenCV binaries
  222. gplayImplementation "com.github.zynkware:Document-Scanning-Android-SDK:$documentScannerVersion"
  223. huaweiImplementation "com.github.zynkware:Document-Scanning-Android-SDK:$documentScannerVersion"
  224. qaImplementation "com.github.zynkware:Document-Scanning-Android-SDK:$documentScannerVersion"
  225. versionDevImplementation "com.github.zynkware:Document-Scanning-Android-SDK:$documentScannerVersion"
  226. spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0'
  227. spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
  228. implementation "com.google.dagger:dagger:$daggerVersion"
  229. implementation "com.google.dagger:dagger-android:$daggerVersion"
  230. implementation "com.google.dagger:dagger-android-support:$daggerVersion"
  231. kapt "com.google.dagger:dagger-compiler:$daggerVersion"
  232. kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
  233. implementation 'org.conscrypt:conscrypt-android:2.5.2'
  234. implementation "com.google.android.exoplayer:exoplayer:$exoplayerVersion"
  235. implementation "com.google.android.exoplayer:extension-okhttp:$exoplayerVersion"
  236. implementation 'com.simplecityapps:recyclerview-fastscroll:2.0.1'
  237. // Shimmer animation
  238. implementation 'com.elyeproj.libraries:loaderviewlibrary:2.0.0'
  239. // dependencies for markdown rendering
  240. implementation "io.noties.markwon:core:$markwonVersion"
  241. implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
  242. implementation "io.noties.markwon:ext-tables:$markwonVersion"
  243. implementation "io.noties.markwon:ext-tasklist:$markwonVersion"
  244. implementation "io.noties.markwon:html:$markwonVersion"
  245. implementation "io.noties.markwon:syntax-highlight:$markwonVersion"
  246. implementation "io.noties:prism4j:$prismVersion"
  247. kapt "io.noties:prism4j-bundler:$prismVersion"
  248. implementation ('org.mnode.ical4j:ical4j:1.0.8') {
  249. ['org.apache.commons','commons-logging'].each {
  250. exclude group: "$it"
  251. }
  252. }
  253. if (!ciBuild) {
  254. debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
  255. }
  256. // dependencies for local unit tests
  257. testImplementation 'junit:junit:4.13.2'
  258. testImplementation "org.mockito:mockito-core:$mockitoVersion"
  259. testImplementation "androidx.test:core:$androidxTestVersion"
  260. testImplementation "org.powermock:powermock-core:$powermockVersion"
  261. testImplementation "org.powermock:powermock-module-junit4:$powermockVersion"
  262. testImplementation "org.powermock:powermock-api-mockito2:$powermockVersion"
  263. testImplementation 'org.json:json:20220320'
  264. testImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion"
  265. testImplementation 'androidx.arch.core:core-testing:2.1.0'
  266. testImplementation "io.mockk:mockk:$mockkVersion"
  267. testImplementation "io.mockk:mockk-android:$mockkVersion"
  268. // dependencies for instrumented tests
  269. // JUnit4 Rules
  270. androidTestImplementation 'androidx.test.ext:junit:1.1.3'
  271. androidTestImplementation "androidx.test:rules:$androidxTestVersion"
  272. // Android JUnit Runner
  273. androidTestImplementation "androidx.test:runner:$androidxTestVersion"
  274. androidTestUtil "androidx.test:orchestrator:$androidxTestVersion"
  275. // Espresso
  276. androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
  277. androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
  278. androidTestImplementation "androidx.test.espresso:espresso-web:$espressoVersion"
  279. androidTestImplementation "androidx.test.espresso:espresso-accessibility:$espressoVersion"
  280. androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
  281. // Mocking support
  282. androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5' // required to allow mocking on API 27 and older
  283. androidTestImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion"
  284. androidTestImplementation "org.mockito:mockito-core:$mockitoVersion"
  285. androidTestImplementation("org.mockito:mockito-android:$mockitoVersion") {
  286. exclude group: "net.bytebuddy", module: "byte-buddy-android"
  287. }
  288. androidTestImplementation "net.bytebuddy:byte-buddy:$byteBuddyVersion"
  289. androidTestImplementation "net.bytebuddy:byte-buddy-android:$byteBuddyVersion"
  290. androidTestImplementation "io.mockk:mockk-android:$mockkVersion"
  291. androidTestImplementation 'androidx.arch.core:core-testing:2.0.1'
  292. androidTestImplementation "com.facebook.testing.screenshot:core:0.15.0"
  293. // UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
  294. // androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
  295. // fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
  296. //androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
  297. androidTestImplementation 'tools.fastlane:screengrab:2.1.1'
  298. implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  299. implementation "com.github.stateless4j:stateless4j:2.6.0"
  300. // upon each update first test: new registration, receive push
  301. gplayImplementation "com.google.firebase:firebase-messaging:23.0.2"
  302. }
  303. configurations.all {
  304. resolutionStrategy{
  305. cacheChangingModulesFor 0, 'seconds'
  306. force 'org.objenesis:objenesis:2.6'
  307. eachDependency { details ->
  308. if ('org.jacoco' == details.requested.group) {
  309. details.useVersion "$jacoco_version"
  310. }
  311. }
  312. }
  313. }
  314. tasks.withType(Test) {
  315. // increased logging for tests
  316. testLogging {
  317. events "passed", "skipped", "failed"
  318. }
  319. }
  320. android.applicationVariants.all { variant ->
  321. variant.outputs.all { output ->
  322. outputFileName = "${output.baseName}-${variant.versionCode}.apk"
  323. }
  324. }
  325. tasks.register("combinedTestReport", JacocoReport) {
  326. jacocoClasspath = configurations['jacocoAnt']
  327. reports {
  328. xml.enabled true
  329. html.enabled true
  330. csv.enabled false
  331. }
  332. additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
  333. sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
  334. classDirectories.setFrom files(subprojects.sourceSets.main.output)
  335. executionData.setFrom project.fileTree(dir: project.buildDir, includes: [
  336. 'jacoco/testGplayDebugUnitTest.exec', 'outputs/code-coverage/connected/flavors/GPLAY/*coverage.ec'
  337. ])
  338. }
  339. task installGitHooks(type: Copy, group: "development") {
  340. description = "Install git hooks"
  341. from("${project.rootDir}/scripts/hooks") {
  342. include '*'
  343. }
  344. into "${project.rootDir}/.git/hooks"
  345. }
  346. detekt {
  347. reports {
  348. xml {
  349. enabled = false
  350. }
  351. }
  352. config = files("detekt.yml")
  353. }
  354. shot {
  355. showOnlyFailingTestsInReports = ciBuild
  356. // CI environment renders some shadows slightly different from local VMs
  357. // Add a 0.5% tolerance to account for that
  358. tolerance = ciBuild ? 0.5: 0
  359. }
  360. jacoco {
  361. toolVersion = "$jacoco_version"
  362. }
  363. spotbugs {
  364. ignoreFailures = true // should continue checking
  365. effort = "max"
  366. reportLevel = "medium"
  367. }
  368. tasks.withType(SpotBugsTask){task ->
  369. String variantNameCap = task.name.replace("spotbugs", "")
  370. String variantName = variantNameCap.substring(0, 1).toLowerCase() + variantNameCap.substring(1)
  371. dependsOn "compile${variantNameCap}Sources"
  372. excludeFilter = file("${project.rootDir}/spotbugs-filter.xml")
  373. classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/classes/")
  374. reports {
  375. xml {
  376. required = false
  377. }
  378. html {
  379. required = true
  380. outputLocation = file("$project.buildDir/reports/spotbugs/spotbugs.html")
  381. stylesheet = 'fancy.xsl'
  382. }
  383. }
  384. }