DEADSOFTWARE

Update version script
[cavedroid.git] / android / build.gradle.kts
1 import java.io.FileInputStream
2 import java.util.Properties
4 private val natives by configurations.creating
6 plugins {
7 id("com.android.application")
8 id("kotlin-android")
9 }
11 private val keystorePropertiesFile = rootProject.file("keystore.properties")
12 private val keystoreProperties = if (keystorePropertiesFile.exists()) {
13 Properties().apply {
14 load(FileInputStream(keystorePropertiesFile))
15 }
16 } else {
17 null
18 }
21 android {
22 namespace = ApplicationInfo.packageName
23 compileSdk = 34
25 sourceSets {
27 named("main") {
28 jniLibs.srcDir("libs")
29 }
31 named("debug") {
32 res.srcDir("src/debug/res")
33 }
35 }
37 compileOptions {
38 sourceCompatibility = ApplicationInfo.sourceCompatibility
39 targetCompatibility = ApplicationInfo.sourceCompatibility
40 }
42 defaultConfig {
43 applicationId = ApplicationInfo.packageName
44 minSdk = 19
45 targetSdk = 34
47 versionCode = ApplicationInfo.versionCode
48 versionName = ApplicationInfo.versionName
50 multiDexEnabled = true
51 }
53 applicationVariants.asSequence()
54 .flatMap { variant -> variant.outputs.asSequence() }
55 .mapNotNull { output -> output as? com.android.build.gradle.internal.api.BaseVariantOutputImpl }
56 .forEach { output -> output.outputFileName = "android-${ApplicationInfo.versionName}.apk" }
58 val releaseConfig = signingConfigs.create("release_config")
59 with(releaseConfig) {
60 storeFile = keystoreProperties?.get("releaseKeystorePath")?.let(::file)
61 storePassword = keystoreProperties?.get("releaseKeystorePassword")?.toString()
62 keyAlias = keystoreProperties?.get("releaseKeyAlias")?.toString()
63 keyPassword = keystoreProperties?.get("releaseKeyPassword")?.toString()
64 }
66 buildTypes {
67 release {
68 isMinifyEnabled = false
69 signingConfig = releaseConfig
70 }
72 debug {
73 applicationIdSuffix = ".debug"
74 }
75 }
77 buildFeatures {
78 buildConfig = true
79 }
80 }
82 // called every time gradle gets executed, takes the native dependencies of
83 // the natives configuration, and extracts them to the proper libs/ folders
84 // so they get packed with the APK.
85 task("copyAndroidNatives") {
86 doFirst {
87 val armeabiV7Dir = file("libs/armeabi-v7a/").apply { mkdirs() }
88 val arm64Dir = file("libs/arm64-v8a/").apply { mkdirs() }
89 val x86Dir = file("libs/x86/").apply { mkdirs() }
90 val amd64Dir = file("libs/x86_64/").apply { mkdirs() }
92 natives.files.forEach { jar ->
93 val outputDir = when {
94 jar.name.endsWith("natives-armeabi-v7a.jar") -> armeabiV7Dir
95 jar.name.endsWith("natives-arm64-v8a.jar") -> arm64Dir
96 jar.name.endsWith("natives-x86.jar") -> x86Dir
97 jar.name.endsWith("natives-x86_64.jar") -> amd64Dir
98 else -> null
99 }
101 if (outputDir != null) {
102 copy {
103 from(zipTree(jar))
104 into(outputDir)
105 include("*.so")
112 tasks.whenTaskAdded {
113 if (name.contains("package")) {
114 dependsOn("copyAndroidNatives")
118 dependencies {
119 implementation((project(":core")))
120 implementation(platform(Dependencies.Kotlin.bom))
122 implementation(Dependencies.LibGDX.gdx)
123 implementation(Dependencies.LibGDX.Android.backend)
125 natives(Dependencies.LibGDX.Android.Natives.armeabi)
126 natives(Dependencies.LibGDX.Android.Natives.arm64)
127 natives(Dependencies.LibGDX.Android.Natives.x86)
128 natives(Dependencies.LibGDX.Android.Natives.x86_64)
130 configurations["implementation"].exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")