|
| 1 | +import com.unciv.build.BuildConfig |
| 2 | +import java.util.* |
| 3 | + |
| 4 | +plugins { |
| 5 | + id("com.android.application") |
| 6 | + id("kotlin-android") |
| 7 | + id("kotlin-android-extensions") |
| 8 | +} |
| 9 | + |
| 10 | +android { |
| 11 | + buildToolsVersion("29.0.2") |
| 12 | + compileSdkVersion(29) |
| 13 | + sourceSets { |
| 14 | + getByName("main").apply { |
| 15 | + manifest.srcFile("AndroidManifest.xml") |
| 16 | + java.srcDirs("src") |
| 17 | + aidl.srcDirs("src") |
| 18 | + renderscript.srcDirs("src") |
| 19 | + res.srcDirs("res") |
| 20 | + assets.srcDirs("assets") |
| 21 | + jniLibs.srcDirs("libs") |
| 22 | + } |
| 23 | + } |
| 24 | + packagingOptions { |
| 25 | + exclude("META-INF/robovm/ios/robovm.xml") |
| 26 | + } |
| 27 | + defaultConfig { |
| 28 | + applicationId = "com.unciv.app" |
| 29 | + minSdkVersion(14) |
| 30 | + targetSdkVersion(29) |
| 31 | + versionCode = BuildConfig.appCodeNumber |
| 32 | + versionName = BuildConfig.appVersion |
| 33 | + |
| 34 | + base.archivesBaseName = "Unciv" |
| 35 | + } |
| 36 | + |
| 37 | + // necessary for Android Work lib |
| 38 | + kotlinOptions { |
| 39 | + jvmTarget = JavaVersion.VERSION_1_8.toString() |
| 40 | + } |
| 41 | + |
| 42 | + // Had to add this crap for Travis to build, it wanted to sign the app |
| 43 | + // but couldn't create the debug keystore for some reason |
| 44 | + |
| 45 | + signingConfigs { |
| 46 | + getByName("debug") { |
| 47 | + storeFile = rootProject.file("debug.keystore") |
| 48 | + keyAlias = "androiddebugkey" |
| 49 | + keyPassword = "android" |
| 50 | + storePassword = "android" |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + buildTypes { |
| 55 | + getByName("release") { |
| 56 | + // Don't add local save files and fonts to release, obviously |
| 57 | + aaptOptions { |
| 58 | + ignoreAssetsPattern = "!SaveFiles:!fonts:!maps:!music:!mods" |
| 59 | + } |
| 60 | + |
| 61 | + isMinifyEnabled = false |
| 62 | + proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") |
| 63 | + } |
| 64 | + |
| 65 | + getByName("debug") { |
| 66 | + // Don't add local save files and fonts to release, obviously |
| 67 | + aaptOptions { |
| 68 | + ignoreAssetsPattern = "!SaveFiles:!fonts:!maps:!music" |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + lintOptions { |
| 73 | + disable("MissingTranslation") |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | + |
| 78 | +// called every time gradle gets executed, takes the native dependencies of |
| 79 | +// the natives configuration, and extracts them to the proper libs/ folders |
| 80 | +// so they get packed with the APK. |
| 81 | +task("copyAndroidNatives") { |
| 82 | + val natives: Configuration by configurations |
| 83 | + |
| 84 | + doFirst { |
| 85 | + file("libs/armeabi/").mkdirs() |
| 86 | + file("libs/armeabi-v7a/").mkdirs() |
| 87 | + file("libs/arm64-v8a/").mkdirs() |
| 88 | + file("libs/x86_64/").mkdirs() |
| 89 | + file("libs/x86/").mkdirs() |
| 90 | + natives.forEach { jar -> |
| 91 | + val outputDir: File? = when { |
| 92 | + jar.name.endsWith("natives-arm64-v8a.jar") -> file("libs/arm64-v8a") |
| 93 | + jar.name.endsWith("natives-armeabi-v7a.jar") -> file("libs/armeabi-v7a") |
| 94 | + jar.name.endsWith("natives-armeabi.jar") -> file("libs/armeabi") |
| 95 | + jar.name.endsWith("natives-x86_64.jar") -> file("libs/x86_64") |
| 96 | + jar.name.endsWith("natives-x86.jar") -> file("libs/x86") |
| 97 | + else -> null |
| 98 | + } |
| 99 | + outputDir?.let { |
| 100 | + copy { |
| 101 | + from(zipTree(jar)) |
| 102 | + into(outputDir) |
| 103 | + include("*.so") |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +tasks.whenTaskAdded { |
| 111 | + if ("package" in name) { |
| 112 | + dependsOn("copyAndroidNatives") |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +tasks.register<JavaExec>("run") { |
| 117 | + val localProperties = project.file("../local.properties") |
| 118 | + val path = if (localProperties.exists()) { |
| 119 | + val properties = Properties() |
| 120 | + localProperties.inputStream().use { properties.load(it) } |
| 121 | + |
| 122 | + properties.getProperty("sdk.dir") ?: System.getenv("ANDROID_HOME") |
| 123 | + } else { |
| 124 | + System.getenv("ANDROID_HOME") |
| 125 | + } |
| 126 | + |
| 127 | + val adb = "$path/platform-tools/adb" |
| 128 | + |
| 129 | + doFirst { |
| 130 | + project.exec { |
| 131 | + commandLine(adb, "shell", "am", "start", "-n", "com.unciv.app/AndroidLauncher") |
| 132 | + } |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +dependencies { |
| 137 | + implementation("androidx.core:core:1.2.0") |
| 138 | + implementation("androidx.work:work-runtime-ktx:2.3.2") |
| 139 | +} |
| 140 | + |
| 141 | +// sets up the Android Eclipse project, using the old Ant based build. |
| 142 | +eclipse { |
| 143 | + jdt { |
| 144 | + sourceCompatibility = JavaVersion.VERSION_1_6 |
| 145 | + targetCompatibility = JavaVersion.VERSION_1_6 |
| 146 | + } |
| 147 | + |
| 148 | + classpath { |
| 149 | + plusConfigurations = plusConfigurations.apply { add(project.configurations.compile.get()) } |
| 150 | + containers("com.android.ide.eclipse.adt.ANDROID_FRAMEWORK", "com.android.ide.eclipse.adt.LIBRARIES") |
| 151 | + } |
| 152 | + |
| 153 | + project { |
| 154 | + name = "${BuildConfig.appName}-android" |
| 155 | + natures("com.android.ide.eclipse.adt.AndroidNature") |
| 156 | + buildCommands.clear() |
| 157 | + buildCommand("com.android.ide.eclipse.adt.ResourceManagerBuilder") |
| 158 | + buildCommand("com.android.ide.eclipse.adt.PreCompilerBuilder") |
| 159 | + buildCommand("org.eclipse.jdt.core.javabuilder") |
| 160 | + buildCommand("com.android.ide.eclipse.adt.ApkBuilder") |
| 161 | + } |
| 162 | +} |
0 commit comments