2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-22 01:51:47 +00:00
kdeconnect-android/build.gradle.kts
Albert Vaca Cintora c6dbadce21
Upgrade to Mockito 5, remove PowerMock and update test
PowerMock is no longer maintained and is only compatible with Mockito 3.
However, modern Mockito supports mocking static methods, so PowerMock is
no longer needed (after adjusting the tests a bit).
2024-05-13 12:31:59 +02:00

253 lines
9.0 KiB
Plaintext

import com.github.jk1.license.LicenseReportExtension
import com.github.jk1.license.render.ReportRenderer
import com.github.jk1.license.render.TextReportRenderer
import java.io.FileNotFoundException
import java.util.Properties
buildscript {
dependencies {
classpath(libs.android.gradlePlugin)
classpath(libs.kotlin.gradlePlugin)
}
}
@Suppress("DSL_SCOPE_VIOLATION") // TODO: remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.kapt)
alias(libs.plugins.dependencyLicenseReport)
}
val licenseResDir = File("$projectDir/build/dependency-license-res")
fun String.runCommand(
workingDir: File = File("."),
timeoutAmount: Long = 60,
timeoutUnit: TimeUnit = TimeUnit.SECONDS
): String = ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex()))
.directory(workingDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
.apply { waitFor(timeoutAmount, timeoutUnit) }
.run {
val error = errorStream.bufferedReader().readText().trim()
if (error.isNotEmpty()) {
throw Exception(error)
}
inputStream.bufferedReader().readText().trim()
}
android {
namespace = "org.kde.kdeconnect_tp"
compileSdk = 34
defaultConfig {
minSdk = 21
targetSdk = 33
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
buildFeatures {
viewBinding = true
compose = true
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_9
targetCompatibility = JavaVersion.VERSION_1_9
// Flag to enable support for the new language APIs
isCoreLibraryDesugaringEnabled = true
}
kotlinOptions {
jvmTarget = "9"
}
androidResources {
generateLocaleConfig = true
}
sourceSets {
getByName("main") {
manifest.srcFile("AndroidManifest.xml")
java.setSrcDirs(listOf("src"))
resources.setSrcDirs(listOf("resources"))
res.setSrcDirs(listOf(licenseResDir, "res"))
assets.setSrcDirs(listOf("assets"))
}
getByName("test") {
java.setSrcDirs(listOf("tests"))
}
}
packaging {
resources {
merges += listOf("META-INF/DEPENDENCIES", "META-INF/LICENSE", "META-INF/NOTICE")
}
}
signingConfigs {
getByName("debug") {
storeFile = file("debug.keystore")
storePassword = "android"
keyAlias = "androiddebugkey"
keyPassword = "android"
}
}
buildTypes {
getByName("debug") {
// We minify by default even on debug builds. This has helped us catch issues where minification would remove files that were actually used (eg: via reflection).
// If you want to locally disable this behavior to speed-up the build, add a line `disableMinifyDebug=true` to your `local.properties` file.
val reader = try {
rootProject.file("local.properties").reader()
} catch (e: FileNotFoundException) {
null
}
val properties = reader?.use { Properties().apply { load(it) } }
val disableMinifyDebug = properties?.getProperty("disableMinifyDebug")?.toBoolean() ?: false
isMinifyEnabled = !disableMinifyDebug
isShrinkResources = !disableMinifyDebug
signingConfig = signingConfigs.getByName("debug")
}
// keep minifyEnabled false above for faster builds; set to 'true'
// when testing to make sure ProGuard/R8 is not deleting important stuff
getByName("release") {
isMinifyEnabled = true
isShrinkResources = true
}
}
lint {
abortOnError = false
checkReleaseBuilds = false
}
testOptions {
unitTests.all {
it.jvmArgs = it.jvmArgs.orEmpty() + listOf(
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.base/java.security=ALL-UNNAMED",
"--add-opens=java.base/sun.security.rsa=ALL-UNNAMED",
"--add-opens=java.base/sun.security.x509=ALL-UNNAMED",
"--add-opens=java.base/java.util=ALL-UNNAMED",
"--add-opens=java.base/java.lang.reflect=ALL-UNNAMED"
)
}
}
applicationVariants.all {
val variant = this
logger.quiet("Found a variant called ${variant.name}")
if (variant.buildType.isDebuggable) {
variant.outputs.all {
val output = this as com.android.build.gradle.internal.api.BaseVariantOutputImpl
if (output.outputFile.name.endsWith(".apk")) {
// Default output filename is "${project.name}-${v.name}.apk". We want
// the Git commit short-hash to be added onto that default filename.
try {
val hash = "git rev-parse --short HEAD".runCommand(workingDir = rootDir)
val newName = "${project.name}-${variant.name}-${hash}.apk"
logger.quiet(" Found an output file ${output.outputFile.name}, renaming to ${newName}")
output.outputFileName = newName
} catch (ignored: Exception) {
logger.warn("Could not make use of the 'git' command-line tool. Output filenames will not be customized.")
}
}
}
}
}
}
dependencies {
coreLibraryDesugaring(libs.android.desugarJdkLibs)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.constraintlayout.compose)
implementation(libs.androidx.compose.ui.tooling.preview)
debugImplementation(libs.androidx.compose.ui.tooling)
implementation(libs.androidx.media)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.preference.ktx)
implementation(libs.androidx.recyclerview)
implementation(libs.androidx.swiperefreshlayout)
implementation(libs.androidx.documentfile)
implementation(libs.androidx.lifecycle.viewmodel.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.extensions)
implementation(libs.androidx.lifecycle.common.java8)
implementation(libs.androidx.gridlayout)
implementation(libs.material)
implementation(libs.disklrucache) //For caching album art bitmaps
implementation(libs.slf4j.handroid)
implementation(libs.apache.sshd.core)
implementation(libs.apache.mina.core) //For some reason, makes sshd-core:0.14.0 work without NIO, which isn't available until Android 8 (api 26)
//implementation("com.github.bright:slf4android:0.1.6") { transitive = true } // For org.apache.sshd debugging
implementation(libs.bcpkix.jdk15on) //For SSL certificate generation
implementation(libs.classindex)
kapt(libs.classindex)
// The android-smsmms library is the only way I know to handle MMS in Android
// (Shouldn't a phone OS make phone things easy?)
// This library was originally authored as com.klinkerapps at https://github.com/klinker41/android-smsmms.
// However, that version is under-loved. I have therefore made "some fixes" and published it.
// Please see https://invent.kde.org/sredman/android-smsmms/-/tree/master
implementation(libs.android.smsmms)
implementation(libs.logger)
implementation(libs.commons.io)
implementation(libs.commons.collections4)
implementation(libs.commons.lang3)
implementation(libs.univocity.parsers)
// Kotlin
implementation(libs.kotlin.stdlib.jdk8)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlinx.coroutines.android)
// Testing
testImplementation(libs.junit)
testImplementation(libs.mockito.core)
testImplementation(libs.jsonassert)
// For device controls
implementation(libs.reactive.streams)
implementation(libs.rxjava)
}
licenseReport {
configurations = LicenseReportExtension.ALL
renderers = arrayOf<ReportRenderer>(TextReportRenderer())
}
tasks.named("generateLicenseReport") {
doLast {
val target = File(licenseResDir, "raw/license")
target.parentFile.mkdirs()
target.writeText(
files(
layout.projectDirectory.file("COPYING"),
layout.buildDirectory.file("reports/dependency-license/THIRD-PARTY-NOTICES.txt")
).joinToString(separator = "\n") {
it.readText()
}
)
}
}
tasks.named("preBuild") {
dependsOn("generateLicenseReport")
}