Add Kotlin and Rust Android agent with signed APK export
This commit is contained in:
1 parent
e366eb5bec
commit
5b3022e1f3
20 files changed
+3568
-2
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import java.util.Properties
|
||||
|
||||
plugins { id("com.android.application"); id("org.jetbrains.kotlin.android") }
|
||||
val signingFile = rootProject.file("signing.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("crosshatch") {
|
||||
storeFile = file(signingValue("storeFile"))
|
||||
storePassword = signingValue("storePassword")
|
||||
keyAlias = signingValue("keyAlias")
|
||||
keyPassword = signingValue("keyPassword")
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
getByName("debug") { signingConfig = signingConfigs.getByName("crosshatch") }
|
||||
getByName("release") { signingConfig = signingConfigs.getByName("crosshatch"); 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}-crosshatch${if (variant == "debug") "-debug" else ""}.apk" }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user