mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-26 11:56:27 -08:00
284 lines
9.4 KiB
Kotlin
284 lines
9.4 KiB
Kotlin
/*
|
|
* This file was generated by the Gradle "init" task.
|
|
*
|
|
* This generated file contains a sample Java Library project to get you started.
|
|
* For more details take a look at the Java Libraries chapter in the Gradle
|
|
* User Manual available at https://docs.gradle.org/6.3/userguide/java_library_plugin.html
|
|
*/
|
|
import com.android.build.gradle.internal.tasks.BaseTask
|
|
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
|
import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated
|
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|
import java.util.Base64
|
|
|
|
plugins {
|
|
kotlin("plugin.serialization")
|
|
id("com.github.gmazzo.buildconfig")
|
|
|
|
id("com.android.application") version "9.2.1"
|
|
id("io.sentry.android.gradle")
|
|
}
|
|
|
|
// SENTRY_* from the repo root .env.local, see .env.example. Real environment variables win.
|
|
val localSentryEnv: Map<String, String> = rootProject.file(".env.local")
|
|
.takeIf { it.isFile }?.readLines().orEmpty()
|
|
.map { it.trim() }
|
|
.filter { it.startsWith("SENTRY_") && '=' in it }
|
|
.associate { it.substringBefore('=').trim() to it.substringAfter('=').trim().removeSurrounding("\"") }
|
|
|
|
fun sentryEnv(name: String): Provider<String> = providers.environmentVariable(name).orElse(localSentryEnv[name] ?: "")
|
|
|
|
kotlin {
|
|
jvmToolchain {
|
|
languageVersion.set(JavaLanguageVersion.of(25))
|
|
}
|
|
}
|
|
java {
|
|
toolchain {
|
|
languageVersion.set(JavaLanguageVersion.of(25))
|
|
}
|
|
}
|
|
|
|
val gitVersionTag = providers.exec {
|
|
commandLine("git", "--no-pager", "tag", "--sort", "-taggerdate", "--points-at", "HEAD", "-l", "v*")
|
|
}.standardOutput.asText.map { it.trim().lineSequence().firstOrNull() ?: "" }
|
|
val gitIsClean = providers.exec {
|
|
commandLine("git", "status", "--porcelain")
|
|
}.standardOutput.asText.map { it.trim().isEmpty() }
|
|
|
|
buildConfig {
|
|
useKotlinOutput { topLevelConstants = true }
|
|
packageName("dev.slimevr.android.buildinfo")
|
|
|
|
buildConfigField("String", "GIT_VERSION_TAG", gitVersionTag.map { "\"$it\"" })
|
|
buildConfigField("boolean", "GIT_CLEAN", gitIsClean.map { it.toString() })
|
|
buildConfigField("String", "SENTRY_DSN", sentryEnv("SENTRY_SERVER_DSN").map { "\"$it\"" })
|
|
val sentryRelease = sentryEnv("SENTRY_RELEASE")
|
|
.zip(gitVersionTag.zip(gitIsClean) { tag, clean -> if (clean) tag else "" }) { forced, tagged -> forced.ifEmpty { tagged } }
|
|
buildConfigField("String", "SENTRY_RELEASE", sentryRelease.map { "\"$it\"" })
|
|
val sentryEnvironment = sentryEnv("SENTRY_ENVIRONMENT").map { it.ifEmpty { "production" } }
|
|
buildConfigField("String", "SENTRY_ENVIRONMENT", sentryEnvironment.map { "\"$it\"" })
|
|
}
|
|
|
|
sentry {
|
|
org.set("slimevr")
|
|
projectName.set("slimevr-server")
|
|
authToken.set(providers.environmentVariable("SENTRY_AUTH_TOKEN"))
|
|
includeProguardMapping.set(true)
|
|
autoUploadProguardMapping.set(
|
|
gitVersionTag.zip(gitIsClean) { tag, clean -> tag.isNotEmpty() && clean }
|
|
.zip(providers.environmentVariable("SENTRY_AUTH_TOKEN").orElse("")) { tagged, token -> tagged && token.isNotEmpty() },
|
|
)
|
|
ignoredBuildTypes.set(setOf("debug"))
|
|
autoInstallation { enabled.set(false) }
|
|
tracingInstrumentation { enabled.set(false) }
|
|
includeSourceContext.set(false)
|
|
uploadNativeSymbols.set(false)
|
|
telemetry.set(false)
|
|
}
|
|
|
|
val copyGuiAssets = tasks.register<Copy>("copyGuiAssets") {
|
|
val target = layout.projectDirectory.dir("src/main/assets/web-gui")
|
|
delete(target)
|
|
from(rootProject.layout.projectDirectory.dir("gui/electron/out/renderer"))
|
|
into(target)
|
|
if (inputs.sourceFiles.isEmpty) {
|
|
throw GradleException("You need to run \"pnpm run build\" first!")
|
|
}
|
|
}
|
|
tasks.preBuild {
|
|
dependsOn(copyGuiAssets)
|
|
}
|
|
|
|
// Set up signing pre/post tasks
|
|
val preSign = tasks.register("preSign") {
|
|
dependsOn(writeTempKeyStore)
|
|
}
|
|
val postSign = tasks.register("postSign") {
|
|
finalizedBy(deleteTempKeyStore)
|
|
}
|
|
tasks.withType<BaseTask> {
|
|
dependsOn(preSign)
|
|
finalizedBy(postSign)
|
|
}
|
|
|
|
// Handle GitHub secret Android KeyStore files
|
|
val envKeyStore: String? = System.getenv("ANDROID_STORE_FILE")?.takeIf { it.isNotBlank() }
|
|
val tempKeyStore = project.layout.buildDirectory.file("tmp/keystore.tmp.jks").get().asFile
|
|
val writeTempKeyStore = tasks.register("writeTempKeyStore") {
|
|
if (envKeyStore != null) {
|
|
doLast {
|
|
tempKeyStore.apply {
|
|
ensureParentDirsCreated()
|
|
tempKeyStore.writeBytes(Base64.getDecoder().decode(envKeyStore))
|
|
tempKeyStore.deleteOnExit()
|
|
}
|
|
}
|
|
finalizedBy(deleteTempKeyStore)
|
|
} else {
|
|
enabled = false
|
|
}
|
|
}
|
|
val deleteTempKeyStore = tasks.register<Delete>("deleteTempKeyStore") {
|
|
if (envKeyStore != null) {
|
|
delete(tempKeyStore)
|
|
} else {
|
|
enabled = false
|
|
}
|
|
}
|
|
|
|
tasks.withType<KotlinCompile> {
|
|
compilerOptions {
|
|
jvmTarget.set(JvmTarget.JVM_25)
|
|
freeCompilerArgs.set(listOf("-Xvalue-classes"))
|
|
}
|
|
}
|
|
|
|
// Set compiler to use UTF-8
|
|
tasks.withType<JavaCompile> {
|
|
options.encoding = "UTF-8"
|
|
}
|
|
tasks.withType<Test> {
|
|
systemProperty("file.encoding", "UTF-8")
|
|
}
|
|
tasks.withType<Javadoc> {
|
|
options.encoding = "UTF-8"
|
|
}
|
|
|
|
repositories {
|
|
google()
|
|
maven(url = "https://jitpack.io")
|
|
mavenCentral()
|
|
}
|
|
|
|
dependencies {
|
|
implementation(project(":server:core"))
|
|
|
|
// Android stuff
|
|
implementation("androidx.appcompat:appcompat:1.7.1")
|
|
implementation("androidx.core:core-ktx:1.17.0")
|
|
implementation("com.google.android.material:material:1.13.0")
|
|
implementation("androidx.constraintlayout:constraintlayout:2.2.1")
|
|
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
|
|
androidTestImplementation("androidx.test.ext:junit:1.3.0")
|
|
androidTestImplementation("androidx.test.espresso:espresso-core:3.7.0")
|
|
|
|
// Serial + firmware flashing
|
|
implementation("com.github.mik3y:usb-serial-for-android:3.7.0")
|
|
implementation("com.github.loucass003:EspflashKotlin:v0.11.0")
|
|
|
|
// mDNS for OSCQuery, resolves to the NsdManager-backed android variant
|
|
implementation("com.appstractive:dns-sd-kt:1.1.0")
|
|
|
|
// Logging
|
|
implementation("io.klogging:klogging:0.11.7")
|
|
|
|
implementation("io.sentry:sentry-android-core:${providers.gradleProperty("sentryVersion").get()}")
|
|
|
|
// WebSocket server + coroutines
|
|
val ktorVersion = "3.4.1"
|
|
implementation("io.ktor:ktor-server-cio:$ktorVersion")
|
|
implementation("io.ktor:ktor-server-websockets:$ktorVersion")
|
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2")
|
|
}
|
|
|
|
// The android block is where you configure all your Android-specific build options.
|
|
android {
|
|
// The app's namespace. Used primarily to access app resources.
|
|
|
|
namespace = "dev.slimevr.android"
|
|
|
|
/* compileSdk specifies the Android API level Gradle should use to
|
|
compile your app. This means your app can use the API features included in
|
|
this API level and lower. */
|
|
|
|
compileSdk = 36
|
|
|
|
/* The defaultConfig block encapsulates default settings and entries for all
|
|
build variants and can override some attributes in main/AndroidManifest.xml
|
|
dynamically from the build system. You can configure product flavors to override
|
|
these values for different versions of your app. */
|
|
|
|
packaging {
|
|
resources.excludes.add("META-INF/*")
|
|
}
|
|
|
|
defaultConfig {
|
|
|
|
// Uniquely identifies the package for publishing.
|
|
applicationId = "dev.slimevr.server.android"
|
|
|
|
// Defines the minimum API level required to run the app.
|
|
minSdk = 26
|
|
|
|
// Specifies the API level used to test the app.
|
|
targetSdk = 36
|
|
|
|
// adds an offset of the version code as we might do apk releases in the middle of actual
|
|
// releases if we failed on bundling or stuff
|
|
val versionCodeOffset = 4
|
|
|
|
// Defines the version number of your app.
|
|
versionCode = providers.exec {
|
|
commandLine("git", "--no-pager", "tag", "-l")
|
|
}.standardOutput.asText.get().trim().split('\n').size +
|
|
versionCodeOffset
|
|
versionName = providers.exec {
|
|
commandLine("git", "describe", "--tags", "--abbrev=8", "--always")
|
|
}.standardOutput.asText.get().trim()
|
|
|
|
logger.lifecycle("i: Configured for SlimeVR Android version \"$versionName\" ($versionCode).")
|
|
|
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
|
}
|
|
|
|
signingConfigs {
|
|
val inputKeyStore: File? = if (envKeyStore != null) {
|
|
logger.lifecycle("i: \"ANDROID_STORE_FILE\" environment variable found, using for signing config.")
|
|
tempKeyStore
|
|
} else {
|
|
file("secrets/keystore.jks").takeIf { it.canRead() && it.length() > 0 }
|
|
}
|
|
|
|
if (inputKeyStore != null) {
|
|
logger.info("i: Configuring signing for Android KeyStore file: \"${inputKeyStore.path}\".")
|
|
|
|
create("release") {
|
|
storeFile = inputKeyStore
|
|
storePassword = System.getenv("ANDROID_STORE_PASSWD")
|
|
keyAlias = System.getenv("ANDROID_KEY_ALIAS") ?: "key0"
|
|
keyPassword = System.getenv("ANDROID_KEY_PASSWD")
|
|
}
|
|
} else {
|
|
logger.warn("w: Android KeyStore file is not valid or not found, skipping signing.")
|
|
}
|
|
}
|
|
|
|
/* The buildTypes block is where you can configure multiple build types.
|
|
By default, the build system defines two build types: debug and release. The
|
|
debug build type is not explicitly shown in the default build configuration,
|
|
but it includes debugging tools and is signed with the debug key. The release
|
|
build type applies ProGuard settings and is not signed by default. */
|
|
|
|
buildTypes {
|
|
|
|
/* By default, Android Studio configures the release build type to enable code
|
|
shrinking, using minifyEnabled, and specifies the default ProGuard rules file. */
|
|
|
|
release {
|
|
isMinifyEnabled = true // Enables code shrinking for the release build type.
|
|
isShrinkResources = true // Enables resource shrinking.
|
|
proguardFiles(
|
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
|
"proguard-rules.pro",
|
|
)
|
|
signingConfig = signingConfigs.findByName("release")
|
|
}
|
|
}
|
|
|
|
compileOptions {
|
|
sourceCompatibility = JavaVersion.VERSION_25
|
|
targetCompatibility = JavaVersion.VERSION_25
|
|
}
|
|
}
|