2023-07-24 14:41:02 +07:00
|
|
|
|
2022-12-23 19:49:08 +07:00
|
|
|
import com.unciv.build.AndroidImagePacker
|
2023-07-24 14:41:02 +07:00
|
|
|
import com.unciv.build.BuildConfig
|
2023-05-15 01:55:36 +07:00
|
|
|
import java.util.Properties
|
2020-05-19 04:14:01 +07:00
|
|
|
|
|
|
|
plugins {
|
|
|
|
id("com.android.application")
|
|
|
|
id("kotlin-android")
|
|
|
|
}
|
|
|
|
|
|
|
|
android {
|
2024-07-28 21:26:42 +07:00
|
|
|
compileSdk = 34
|
2020-05-19 04:14:01 +07:00
|
|
|
sourceSets {
|
|
|
|
getByName("main").apply {
|
|
|
|
manifest.srcFile("AndroidManifest.xml")
|
|
|
|
java.srcDirs("src")
|
|
|
|
aidl.srcDirs("src")
|
|
|
|
renderscript.srcDirs("src")
|
|
|
|
res.srcDirs("res")
|
|
|
|
assets.srcDirs("assets")
|
|
|
|
jniLibs.srcDirs("libs")
|
|
|
|
}
|
|
|
|
}
|
2024-01-31 01:17:51 +07:00
|
|
|
packaging {
|
2022-05-17 22:37:12 +07:00
|
|
|
resources.excludes += "META-INF/robovm/ios/robovm.xml"
|
|
|
|
// part of kotlinx-coroutines-android, should not go into the apk
|
|
|
|
resources.excludes += "DebugProbesKt.bin"
|
2020-05-19 04:14:01 +07:00
|
|
|
}
|
|
|
|
defaultConfig {
|
2024-07-17 21:06:40 +07:00
|
|
|
namespace = BuildConfig.identifier
|
|
|
|
applicationId = BuildConfig.identifier
|
2021-12-14 01:12:53 +07:00
|
|
|
minSdk = 21
|
2024-08-05 02:05:06 +07:00
|
|
|
targetSdk = 34 // See #5044
|
2020-05-19 04:14:01 +07:00
|
|
|
versionCode = BuildConfig.appCodeNumber
|
|
|
|
versionName = BuildConfig.appVersion
|
|
|
|
|
2022-05-19 07:12:18 +07:00
|
|
|
base.archivesName.set("Unciv")
|
2020-05-19 04:14:01 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
// necessary for Android Work lib
|
|
|
|
kotlinOptions {
|
|
|
|
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Had to add this crap for Travis to build, it wanted to sign the app
|
|
|
|
// but couldn't create the debug keystore for some reason
|
|
|
|
|
|
|
|
signingConfigs {
|
|
|
|
getByName("debug") {
|
2024-07-02 03:24:25 +07:00
|
|
|
storeFile = rootProject.file("android/debug.keystore")
|
2020-05-19 04:14:01 +07:00
|
|
|
keyAlias = "androiddebugkey"
|
|
|
|
keyPassword = "android"
|
|
|
|
storePassword = "android"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buildTypes {
|
2024-04-25 19:44:40 +07:00
|
|
|
debug {
|
|
|
|
isDebuggable = true
|
|
|
|
}
|
|
|
|
release {
|
2022-05-19 07:12:18 +07:00
|
|
|
// If you make this true you get a version of the game that just flat-out doesn't run
|
2021-12-12 00:48:34 +07:00
|
|
|
isMinifyEnabled = false
|
2020-05-19 04:14:01 +07:00
|
|
|
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
|
2024-04-25 19:44:40 +07:00
|
|
|
isDebuggable = false
|
2020-05-19 04:14:01 +07:00
|
|
|
}
|
2020-06-02 02:30:16 +07:00
|
|
|
}
|
2024-04-25 19:44:40 +07:00
|
|
|
|
2021-08-23 02:00:34 +07:00
|
|
|
lint {
|
2022-05-19 07:12:18 +07:00
|
|
|
disable += "MissingTranslation" // see res/values/strings.xml
|
2020-05-19 04:14:01 +07:00
|
|
|
}
|
2021-05-07 17:18:48 +07:00
|
|
|
compileOptions {
|
2021-09-05 23:36:35 +07:00
|
|
|
targetCompatibility = JavaVersion.VERSION_1_8
|
2022-08-05 20:10:56 +07:00
|
|
|
isCoreLibraryDesugaringEnabled = true
|
2021-05-07 17:18:48 +07:00
|
|
|
}
|
2021-08-23 02:00:34 +07:00
|
|
|
androidResources {
|
|
|
|
// Don't add local save files and fonts to release, obviously
|
|
|
|
ignoreAssetsPattern = "!SaveFiles:!fonts:!maps:!music:!mods"
|
|
|
|
}
|
2024-01-28 17:35:29 +07:00
|
|
|
buildFeatures {
|
|
|
|
renderScript = true
|
|
|
|
aidl = true
|
|
|
|
}
|
2020-05-19 04:14:01 +07:00
|
|
|
}
|
|
|
|
|
2022-12-23 19:49:08 +07:00
|
|
|
task("texturePacker") {
|
|
|
|
doFirst {
|
|
|
|
logger.info("Calling TexturePacker")
|
2023-05-10 15:43:53 +07:00
|
|
|
AndroidImagePacker.packImages(projectDir.path)
|
2022-12-23 19:49:08 +07:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 04:14:01 +07:00
|
|
|
|
|
|
|
// called every time gradle gets executed, takes the native dependencies of
|
|
|
|
// the natives configuration, and extracts them to the proper libs/ folders
|
|
|
|
// so they get packed with the APK.
|
|
|
|
task("copyAndroidNatives") {
|
|
|
|
val natives: Configuration by configurations
|
|
|
|
|
|
|
|
doFirst {
|
2021-06-10 01:37:27 +07:00
|
|
|
val rx = Regex(""".*natives-([^.]+)\.jar$""")
|
2020-05-19 04:14:01 +07:00
|
|
|
natives.forEach { jar ->
|
2021-06-10 01:37:27 +07:00
|
|
|
if (rx.matches(jar.name)) {
|
|
|
|
val outputDir = file(rx.replace(jar.name) { "libs/" + it.groups[1]!!.value })
|
|
|
|
outputDir.mkdirs()
|
2020-05-19 04:14:01 +07:00
|
|
|
copy {
|
|
|
|
from(zipTree(jar))
|
|
|
|
into(outputDir)
|
|
|
|
include("*.so")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-23 19:49:08 +07:00
|
|
|
dependsOn("texturePacker")
|
2020-05-19 04:14:01 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
tasks.whenTaskAdded {
|
2021-08-13 00:42:49 +07:00
|
|
|
// See https://github.com/yairm210/Unciv/issues/4842
|
|
|
|
if ("package" in name || "assemble" in name || "bundleRelease" in name) {
|
2020-05-19 04:14:01 +07:00
|
|
|
dependsOn("copyAndroidNatives")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register<JavaExec>("run") {
|
|
|
|
val localProperties = project.file("../local.properties")
|
|
|
|
val path = if (localProperties.exists()) {
|
|
|
|
val properties = Properties()
|
|
|
|
localProperties.inputStream().use { properties.load(it) }
|
|
|
|
|
|
|
|
properties.getProperty("sdk.dir") ?: System.getenv("ANDROID_HOME")
|
|
|
|
} else {
|
|
|
|
System.getenv("ANDROID_HOME")
|
|
|
|
}
|
|
|
|
|
|
|
|
val adb = "$path/platform-tools/adb"
|
|
|
|
|
|
|
|
doFirst {
|
|
|
|
project.exec {
|
|
|
|
commandLine(adb, "shell", "am", "start", "-n", "com.unciv.app/AndroidLauncher")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2023-09-06 16:00:30 +07:00
|
|
|
implementation("androidx.core:core-ktx:1.10.1")
|
|
|
|
implementation("androidx.work:work-runtime-ktx:2.8.1")
|
2022-08-05 20:10:56 +07:00
|
|
|
// Needed to convert e.g. Android 26 API calls to Android 21
|
2022-08-08 03:51:02 +07:00
|
|
|
// If you remove this run `./gradlew :android:lintDebug` to ensure everything's okay.
|
|
|
|
// If you want to upgrade this, check it's working by building an apk,
|
|
|
|
// or by running `./gradlew :android:assembleRelease` which does that
|
2022-08-05 20:10:56 +07:00
|
|
|
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
|
2020-05-19 04:14:01 +07:00
|
|
|
}
|