64 lines
3.0 KiB
Kotlin
64 lines
3.0 KiB
Kotlin
import java.util.Properties
|
|
|
|
plugins { id("com.android.application"); id("org.jetbrains.kotlin.android") }
|
|
val signingProfile = providers.gradleProperty("adsSigning").orElse("crosshatch").get()
|
|
require(signingProfile in listOf("crosshatch", "zhanxun")) { "Unsupported adsSigning profile" }
|
|
val signingFile = rootProject.file(if (signingProfile == "crosshatch") "signing.local.properties" else "signing.zhanxun.local.properties")
|
|
val crosshatchProperties = Properties().apply {
|
|
if (signingFile.isFile) signingFile.inputStream().use { load(it) }
|
|
}
|
|
fun signingValue(name: String): String = crosshatchProperties.getProperty(name)
|
|
?: providers.environmentVariable("ADS_SIGNING_${name.uppercase()}").orNull
|
|
?: error("Missing signing property $name. Configure signing.local.properties (Git ignored).")
|
|
val agentProperties = Properties().apply {
|
|
rootProject.file("agent.local.properties").inputStream().use { load(it) }
|
|
}
|
|
val agentToken = agentProperties.getProperty("agentToken") ?: error("Missing agentToken in agent.local.properties")
|
|
require(agentToken.length >= 32 && agentToken.all { it.code in 33..126 }) { "Invalid Agent token" }
|
|
android {
|
|
buildFeatures { buildConfig = true }
|
|
|
|
namespace = "com.ttstd.ads"
|
|
compileSdk = 35
|
|
defaultConfig {
|
|
buildConfigField("String", "AGENT_TOKEN", "\"" + agentToken.replace("\\", "\\\\").replace("\"", "\\\"") + "\"")
|
|
applicationId = "com.ttstd.ads"; minSdk = 23; targetSdk = 35; versionCode = 2; versionName = "0.1.1"; ndk { abiFilters += listOf("arm64-v8a", "armeabi-v7a", "x86_64") } }
|
|
signingConfigs {
|
|
create(signingProfile) {
|
|
storeFile = file(signingValue("storeFile"))
|
|
storePassword = signingValue("storePassword")
|
|
keyAlias = signingValue("keyAlias")
|
|
keyPassword = signingValue("keyPassword")
|
|
}
|
|
}
|
|
buildTypes {
|
|
getByName("debug") { signingConfig = signingConfigs.getByName(signingProfile) }
|
|
getByName("release") { signingConfig = signingConfigs.getByName(signingProfile); isMinifyEnabled = false }
|
|
}
|
|
compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 }
|
|
kotlinOptions { jvmTarget = "17" }
|
|
packaging { jniLibs.useLegacyPackaging = true }
|
|
}
|
|
tasks.register("verifyNative") {
|
|
doLast {
|
|
listOf("arm64-v8a", "armeabi-v7a", "x86_64").forEach {
|
|
check(file("src/main/jniLibs/$it/libads_android.so").isFile) { "Missing JNI library for $it. Run scripts/build-native.ps1 first." }
|
|
}
|
|
}
|
|
}
|
|
tasks.named("preBuild") { dependsOn("verifyNative") }
|
|
|
|
// Export deliverables after a successful assembly; bin/apk is Git ignored.
|
|
tasks.matching { it.name == "assembleRelease" || it.name == "assembleDebug" }.configureEach {
|
|
val variant = if (name == "assembleRelease") "release" else "debug"
|
|
doLast {
|
|
val source = layout.buildDirectory.file("outputs/apk/$variant/app-$variant.apk").get().asFile
|
|
check(source.isFile) { "APK missing: $source" }
|
|
copy {
|
|
from(source)
|
|
into(rootProject.file("../bin/apk"))
|
|
rename { "ads-android-agent-${android.defaultConfig.versionName}-${signingProfile}${if (variant == "debug") "-debug" else ""}.apk" }
|
|
}
|
|
}
|
|
}
|