plugins { id 'com.android.application' } apply plugin: 'kotlin-android' apply plugin: 'org.jetbrains.kotlin.plugin.compose' def gitValue = { List arguments -> try { def output = providers.exec { commandLine(['git'] + arguments) workingDir rootProject.projectDir ignoreExitValue = true } output.result.get().exitValue == 0 ? output.standardOutput.asText.get().trim() : null } catch (Exception ignored) { null } } def buildLabel = providers.environmentVariable('DROIDDECK_BUILD_LABEL').getOrNull() if (buildLabel == null || buildLabel.trim().isEmpty()) { def eventName = providers.environmentVariable('GITHUB_EVENT_NAME').getOrNull() def eventPath = providers.environmentVariable('GITHUB_EVENT_PATH').getOrNull() if (eventName == 'pull_request_target' && eventPath) { try { def eventFile = layout.file(providers.provider { new File(eventPath) }) def eventText = providers.fileContents(eventFile).asText.get() def pullRequest = new groovy.json.JsonSlurper().parseText(eventText).pull_request if (pullRequest?.number && pullRequest?.head?.sha) { buildLabel = "pr${pullRequest.number} at ${pullRequest.head.sha.take(7)}" } } catch (Exception ignored) { } } if (buildLabel == null || buildLabel.trim().isEmpty()) { def branch = providers.environmentVariable('GITHUB_REF_NAME').getOrNull() ?: gitValue(['branch', '--show-current']) ?: 'local' def commit = providers.environmentVariable('GITHUB_SHA').getOrNull() ?.take(7) ?: gitValue(['rev-parse', '--short=7', 'HEAD']) ?: 'unknown' buildLabel = "${branch} at ${commit}" } } def buildOrigin = providers.environmentVariable('GITHUB_ACTIONS').getOrNull() == 'true' ? 'remote' : 'local' def treeState = providers.environmentVariable('DROIDDECK_BUILD_TREE_STATE').getOrNull() if (!(treeState in ['clean', 'dirty'])) { def status = gitValue(['status', '--porcelain']) treeState = status == null ? 'unknown' : (status.isEmpty() ? 'clean' : 'dirty') } buildLabel = "${buildOrigin} ${treeState} ยท ${buildLabel}" def escapedBuildLabel = buildLabel.replace('\\', '\\\\').replace('"', '\\"') def sourceCommit = providers.environmentVariable('DROIDDECK_SOURCE_COMMIT').getOrNull() ?: providers.environmentVariable('GITHUB_SHA').getOrNull() ?: gitValue(['rev-parse', 'HEAD']) ?: '' def prNumber = (providers.environmentVariable('DROIDDECK_PR_NUMBER').getOrNull() ?: '0').with { it.isInteger() ? it : '0' } def ciBuild = providers.environmentVariable('GITHUB_ACTIONS').getOrNull() == 'true' def releaseSigner = rootProject.file('keystore/release-signer.sha256').text.trim() def commitTime = (gitValue(['show', '-s', '--format=%ct', 'HEAD']) ?: '0').with { it.isLong() ? it : '0' } def desktopKde = rootProject.file('tools/desktop-kde/release.env').readLines() .findAll { it.contains('=') && !it.startsWith('#') } .collectEntries { def kv = it.split('=', 2); [(kv[0].trim()): kv[1].trim()] } def desktopRemovalSources = new groovy.json.JsonSlurper().parse(file('src/main/assets/desktop-removal/sources.json')) if (desktopRemovalSources.archives[desktopKde.DESKTOP_KDE_TAG] != desktopKde.DESKTOP_KDE_SHA256) { throw new GradleException('Desktop removal inventories do not match the pinned archive') } if (!file('src/main/assets/desktop-removal/versions.txt').readLines().contains(desktopKde.DESKTOP_KDE_TAG)) { throw new GradleException('Regenerate desktop removal inventories for ' + desktopKde.DESKTOP_KDE_TAG) } def variantSuffixes = rootProject.file('tools/release/variants.txt').readLines() .findAll { it.trim() && !it.startsWith('#') } .collect { def f = it.trim().split(/\s+/); "${f[1]}=${f[2] == '-' ? '' : f[2]}" } .join(';') android { namespace 'com.droiddeck.launcher' compileSdk 34 ndkVersion project.findProperty('ndkVersion') ?: '27.3.13750724' defaultConfig { applicationId "com.droiddeck.launcher" minSdkVersion 26 targetSdkVersion 28 versionCode 13 versionName "0.4.0" buildConfigField "String", "BUILD_LABEL", "\"${escapedBuildLabel}\"" buildConfigField "String", "SOURCE_COMMIT", "\"${sourceCommit}\"" buildConfigField "int", "PR_NUMBER", "${prNumber}" buildConfigField "boolean", "CI_BUILD", "${ciBuild}" buildConfigField "String", "RELEASE_SIGNER", "\"${releaseSigner}\"" buildConfigField "long", "COMMIT_TIME", "${commitTime}L * 1000L" buildConfigField "String", "VARIANT_SUFFIXES", "\"${variantSuffixes}\"" buildConfigField "String", "SGDB_API_KEY", "\"${System.getenv("SGDB_API_KEY") ?: project.findProperty("sgdbApiKey") ?: ""}\"" buildConfigField "String", "DESKTOP_KDE_TAG", "\"${desktopKde.DESKTOP_KDE_TAG}\"" buildConfigField "String", "DESKTOP_KDE_URL", "\"https://github.com/${desktopKde.DESKTOP_KDE_REPO}/releases/download/${desktopKde.DESKTOP_KDE_TAG}/desktop-kde.tar.zst\"" buildConfigField "String", "DESKTOP_KDE_SHA256", "\"${desktopKde.DESKTOP_KDE_SHA256}\"" buildConfigField "long", "DESKTOP_KDE_SIZE", "${desktopKde.DESKTOP_KDE_SIZE}L" ndk { abiFilters 'arm64-v8a' } externalNativeBuild { cmake { arguments '-DANDROID_STL=c++_shared' } } } externalNativeBuild { cmake { path 'src/main/cpp/CMakeLists.txt' version '3.22.1' } } signingConfigs { testkey { storeFile file("${rootDir}/keystore/testkey.p12") storeType "PKCS12" storePassword "android" keyAlias "testkey" keyPassword "android" enableV1Signing = true enableV2Signing = true enableV3Signing = true } } buildTypes { debug { minifyEnabled false signingConfig signingConfigs.testkey } release { minifyEnabled false signingConfig signingConfigs.testkey } } lint { disable 'ExpiredTargetSdkVersion' } packagingOptions { resources { excludes += ['META-INF/versions/9/OSGI-INF/MANIFEST.MF'] } jniLibs { useLegacyPackaging = true pickFirsts += ['**/libtermux.so'] } } buildFeatures { prefab true compose true buildConfig true } testOptions { unitTests.returnDefaultValues = true unitTests.includeAndroidResources = true } compileOptions { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { jvmTarget = '17' } } def stageSessionScripts = tasks.register('stageSessionScripts', Copy) { from(rootProject.file('tools/linuxfs/overlay')) { include 'usr/local/bin/droiddeck-*', 'usr/local/bin/steam-compatibility', 'usr/bin/**' } into(layout.projectDirectory.dir('src/main/assets/linuxfs')) } tasks.named('preBuild').configure { dependsOn(stageSessionScripts) } def runtimeAssetsDir = layout.buildDirectory.dir('runtimeAssets') def stageRuntimeAssets = tasks.register('stageRuntimeAssets', Sync) { dependsOn(stageSessionScripts) from(layout.projectDirectory.dir('src/main/assets')) { exclude 'pulseaudio.tzst' } from(layout.buildDirectory.dir('prepared-assets')) into(runtimeAssetsDir) } android.sourceSets.main.assets.setSrcDirs([runtimeAssetsDir]) tasks.named('preBuild').configure { dependsOn(stageRuntimeAssets) } def verifyRuntimeInputs = tasks.register('verifyRuntimeInputs', Exec) { mustRunAfter(stageSessionScripts, stageRuntimeAssets) workingDir rootProject.projectDir commandLine 'python3', 'tools/release/runtime_inputs.py', 'verify' } tasks.configureEach { task -> if (task.name in ['packageDebug', 'packageRelease']) task.dependsOn(verifyRuntimeInputs) } def rustCrateDir = layout.projectDirectory.dir('src/main/rust/stores') def rustJniLibsDir = layout.buildDirectory.dir('rustJniLibs') def skipRust = (project.findProperty('skipRust') ?: 'false').toString().toBoolean() def buildRustStores = tasks.register('buildRustStores', Exec) { description = 'Cross-compiles the store download engines (libdroiddeckstores.so) with cargo-ndk.' onlyIf { !skipRust } inputs.dir(rustCrateDir.dir('src')) inputs.files(rustCrateDir.file('Cargo.toml'), rustCrateDir.file('Cargo.lock')) inputs.property('ndkVersion', android.ndkVersion) if (!skipRust) inputs.property('rustToolchain', providers.exec { environment 'PATH', "${System.getProperty('user.home')}/.cargo/bin${File.pathSeparator}${System.getenv('PATH')}" commandLine 'rustup', 'run', 'stable', 'rustc', '-Vv' }.standardOutput.asText) outputs.dir(rustJniLibsDir) workingDir rustCrateDir def cargoBin = "${System.getProperty('user.home')}/.cargo/bin" environment 'PATH', "${cargoBin}${File.pathSeparator}${System.getenv('PATH')}" environment 'ANDROID_NDK_HOME', android.ndkDirectory.absolutePath environment 'CARGO_TERM_COLOR', 'never' if (!skipRust) environment 'RUSTC', providers.exec { commandLine 'rustup', 'which', '--toolchain', 'stable', 'rustc' }.standardOutput.asText.get().trim() commandLine 'rustup', 'run', 'stable', 'cargo', 'ndk', '--target', 'arm64-v8a', '--platform', '26', '--output-dir', rustJniLibsDir.get().asFile.absolutePath, 'build', '--release', '--locked' } if (!skipRust) android.sourceSets.main.jniLibs.srcDir(rustJniLibsDir) tasks.named('preBuild').configure { dependsOn(buildRustStores) } dependencies { implementation 'org.khronos.openxr:openxr_loader_for_android:1.1.49' implementation 'com.github.luben:zstd-jni:1.5.7-4@aar' implementation 'org.apache.commons:commons-compress:1.27.1' implementation 'org.tukaani:xz:1.10' implementation platform('androidx.compose:compose-bom:2024.02.00') implementation 'androidx.compose.ui:ui' implementation 'androidx.compose.material3:material3' implementation 'androidx.compose.ui:ui-tooling-preview' debugImplementation 'androidx.compose.ui:ui-tooling' implementation 'androidx.activity:activity-compose:1.8.2' implementation 'androidx.compose.material:material-icons-extended' implementation 'io.coil-kt:coil-compose:2.6.0' implementation 'com.caverock:androidsvg-aar:1.4' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3' implementation 'com.flyfishxu:kadb-android:1.2.1' implementation 'com.termux.termux-app:terminal-view:0.118.0' testImplementation 'junit:junit:4.13.2' testImplementation 'org.robolectric:robolectric:4.16.1' testImplementation 'androidx.compose.ui:ui-test-junit4' testRuntimeOnly 'com.github.luben:zstd-jni:1.5.7-4@jar' }