build.gradle.kts 7.4 KB
Newer Older
Antoine POPINEAU's avatar
Antoine POPINEAU committed
1
import org.jetbrains.kotlin.konan.properties.hasProperty
2
import java.io.FileInputStream
3
import java.util.Properties
4
5
6
7
8

plugins {
  id("com.android.application")
  id("kotlin-android")

9
  id("org.jlleitschuh.gradle.ktlint") version "10.2.1"
Ryan Harg's avatar
Ryan Harg committed
10
  id("com.gladed.androidgitversion") version "0.4.14"
11
  id("com.github.triplet.play") version "3.7.0"
12
  id("de.mobilej.unmock")
Ryan Harg's avatar
Ryan Harg committed
13
  id("com.github.ben-manes.versions")
14
  jacoco
15
16
17
}

val props = Properties().apply {
18
19
20
21
  try {
    load(FileInputStream(rootProject.file("local.properties")))
  } catch (e: Exception) {
  }
22
23
}

24
25
unMock {
  keep = listOf("android.net.Uri")
26
27
}

28
androidGitVersion {
Ryan Harg's avatar
Ryan Harg committed
29
  codeFormat = "MMNNPPBBB" // Keep in sync with version_code() in dist/create_release.sh
30
31
32
  format = "%tag%%-count%%-commit%%-branch%"
}

33
34
35
36
37
38
android {
  compileOptions {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
  }

Ryan Harg's avatar
Ryan Harg committed
39
40
41
42
  testCoverage {
    version = Versions.jacoco
  }

43
  kotlinOptions {
44
    jvmTarget = JavaVersion.VERSION_1_8.toString()
45
46
  }

47
48
49
50
  buildFeatures {
    viewBinding = true
  }

Ryan Harg's avatar
Ryan Harg committed
51
  lint {
Ryan Harg's avatar
Ryan Harg committed
52
    disable += listOf("MissingTranslation", "ExtraTranslation")
Ryan Harg's avatar
Ryan Harg committed
53
54
  }

Ryan Harg's avatar
Ryan Harg committed
55
  compileSdk = 31
56
57
58

  defaultConfig {

Ryan Harg's avatar
Ryan Harg committed
59
    applicationId = "audio.funkwhale.ffa"
60

Ryan Harg's avatar
Ryan Harg committed
61
    versionCode = androidGitVersion.code()
62
    versionName = androidGitVersion.name()
63

Ryan Harg's avatar
Ryan Harg committed
64
65
66
67
68
    minSdk = 24
    targetSdk = 30

    testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

69
    manifestPlaceholders["appAuthRedirectScheme"] = "urn"
70
71
72
  }

  signingConfigs {
Georg Krause's avatar
Georg Krause committed
73

74
    create("release") {
Georg Krause's avatar
Georg Krause committed
75
76
77
78
79
80
81
82
83
84
85
86
87
      if (project.hasProperty("signing.store")) {
        storeFile = file(project.findProperty("signing.store")!!)
        storePassword = project.findProperty("signing.store_passphrase")!!.toString()
        keyAlias = "ffa"
        keyPassword = project.findProperty("signing.key_passphrase")!!.toString()
      }
    }
    getByName("debug") {
      if (project.hasProperty("signing.store")) {
        storeFile = file(project.findProperty("signing.store")!!)
        storePassword = project.findProperty("signing.store_passphrase")!!.toString()
        keyAlias = "ffa"
        keyPassword = project.findProperty("signing.key_passphrase")!!.toString()
88
89
90
91
      }
    }
  }

92
  testOptions {
93
94
95
96
97
98
    execution = "ANDROID_TEST_ORCHESTRATOR"
    animationsDisabled = true
    unitTests {
      isReturnDefaultValues = true
      isIncludeAndroidResources = true
    }
99
100
  }

101
  buildTypes {
102
103
    getByName("debug") {
      isDebuggable = true
104
      applicationIdSuffix = ".dev"
105

Ryan Harg's avatar
Ryan Harg committed
106
107
      isTestCoverageEnabled = true

Georg Krause's avatar
Georg Krause committed
108
109
110
111
      if (project.hasProperty("signing.store")) {
        signingConfig = signingConfigs.getByName("debug")
      }

112
113
114
      resValue("string", "debug.hostname", props.getProperty("debug.hostname", ""))
      resValue("string", "debug.username", props.getProperty("debug.username", ""))
      resValue("string", "debug.password", props.getProperty("debug.password", ""))
115
116
    }

117
    getByName("release") {
118

Georg Krause's avatar
Georg Krause committed
119
      if (project.hasProperty("signing.store")) {
120
121
        signingConfig = signingConfigs.getByName("release")
      }
122

123
124
125
126
      resValue("string", "debug.hostname", "")
      resValue("string", "debug.username", "")
      resValue("string", "debug.password", "")

127
128
      isMinifyEnabled = true
      isShrinkResources = true
129

130
131
132
133
      proguardFiles(
        getDefaultProguardFile("proguard-android-optimize.txt"),
        "proguard-rules.pro"
      )
134
135
136
137
138
139
140
141
142
143
    }
  }
}

ktlint {
  debug.set(false)
  verbose.set(false)
}

play {
144
  enabled.set(props.hasProperty("play.credentials"))
145

146
147
148
149
  if (enabled.get()) {
    serviceAccountCredentials.set(file(props.getProperty("play.credentials")))
    defaultToAppBundles.set(true)
    track.set("beta")
150
151
152
153
  }
}

dependencies {
154
  implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))
155

156
  implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin}")
157
  implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
158
  implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0")
159

160
  implementation("androidx.appcompat:appcompat:1.4.1")
161
  implementation("androidx.core:core-ktx:1.7.0")
162
  implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.4.1")
163
  implementation("androidx.coordinatorlayout:coordinatorlayout:1.2.0")
164
  implementation("androidx.preference:preference-ktx:1.2.0")
165
  implementation("androidx.recyclerview:recyclerview:1.2.1")
166
  implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
167
  implementation("com.google.android.material:material:1.5.0")
168
  implementation("com.android.support.constraint:constraint-layout:2.0.4")
169

170
171
172
  implementation("com.google.android.exoplayer:exoplayer-core:${Versions.exoPlayer}")
  implementation("com.google.android.exoplayer:exoplayer-ui:${Versions.exoPlayer}")
  implementation("com.google.android.exoplayer:extension-mediasession:${Versions.exoPlayer}")
Ryan Harg's avatar
Ryan Harg committed
173

174
175
176
177
  implementation("io.insert-koin:koin-core:${Versions.koin}")
  implementation("io.insert-koin:koin-android:${Versions.koin}")
  testImplementation("io.insert-koin:koin-test:${Versions.koin}")

178
  implementation("com.github.PaulWoitaschek.ExoPlayer-Extensions:extension-opus:${Versions.exoPlayerExtensions}") {
179
180
    isTransitive = false
  }
181
  implementation("com.github.PaulWoitaschek.ExoPlayer-Extensions:extension-flac:${Versions.exoPlayerExtensions}") {
182
183
    isTransitive = false
  }
184

185
186
187
188
189
190
  implementation("com.aliassadi:power-preference-lib:${Versions.powerPreference}")
  implementation("com.github.kittinunf.fuel:fuel:${Versions.fuel}")
  implementation("com.github.kittinunf.fuel:fuel-coroutines:${Versions.fuel}")
  implementation("com.github.kittinunf.fuel:fuel-android:${Versions.fuel}")
  implementation("com.github.kittinunf.fuel:fuel-gson:${Versions.fuel}")
  implementation("com.google.code.gson:gson:${Versions.gson}")
191
  implementation("com.squareup.picasso:picasso:2.71828")
192
  implementation("jp.wasabeef:picasso-transformations:2.4.0")
193
  implementation("net.openid:appauth:${Versions.openIdAppAuth}")
Ryan Harg's avatar
Ryan Harg committed
194

195
  testImplementation("junit:junit:4.13.2")
196
  testImplementation("io.mockk:mockk:1.12.3")
197
  testImplementation("androidx.test:core:1.4.0")
198
  testImplementation("io.strikt:strikt-core:${Versions.strikt}")
Ryan Harg's avatar
Ryan Harg committed
199
  testImplementation("org.robolectric:robolectric:${Versions.robolectric}")
Ryan Harg's avatar
Ryan Harg committed
200
201

  androidTestImplementation("io.mockk:mockk-android:${Versions.mockk}")
202
203
204
205
}

project.afterEvaluate {

Ryan Harg's avatar
Ryan Harg committed
206
207
208
209
210
211
212
213
214
215
216
217
218
219
  tasks.withType<Test> {

    configure<JacocoTaskExtension> {
      isIncludeNoLocationClasses = true
      excludes = listOf("jdk.internal.*")
    }
  }

  tasks.create("jacocoTestReport", type = JacocoReport::class) {
    dependsOn("testDebugUnitTest", "createDebugCoverageReport")

    group = "Verification"
    description = "Creates a Jacoco Coverage report"

220
221
222
223
    reports {
      xml.required.set(true)
      csv.required.set(true)
      html.required.set(true)
224
    }
Ryan Harg's avatar
Ryan Harg committed
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243

    val fileFilter = listOf(
      "**/R.class",
      "**/R$*.class",
      "**/BuildConfig.*",
      "**/Manifest*.*",
      "**/*Test*.*",
      "android/**/*.*",
      "**/*$[0-9].*"
    )

    val debugTree = fileTree("${project.buildDir}/tmp/kotlin-classes/debug") {
      setExcludes(fileFilter)
    }
    val mainSrc = "${project.projectDir}/src/main/java"

    sourceDirectories.setFrom(files(listOf(mainSrc)))
    classDirectories.setFrom(files(listOf(debugTree)))

Ryan Harg's avatar
Ryan Harg committed
244
245
246
247
248
249
250
    executionData.setFrom(
      fileTree(project.buildDir) {
        setIncludes(
          listOf(
            "outputs/unit_test_code_coverage/debugUnitTest/*.exec",
            "outputs/code_coverage/debugAndroidTest/connected/**/*.ec"
          )
Ryan Harg's avatar
Ryan Harg committed
251
        )
Ryan Harg's avatar
Ryan Harg committed
252
253
      }
    )
254
  }
255
}