-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle.kts
99 lines (77 loc) · 2.89 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
plugins {
kotlin("jvm") version "1.6.10"
}
java.sourceSets["main"].java {
srcDir("src")
}
val mindustryVersion = "v135"
val jarName = "stingray"
repositories {
mavenCentral()
maven("https://jitpack.io")
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
compileOnly("com.github.Anuken.Arc:arc-core:$mindustryVersion")
compileOnly("com.github.Anuken.Mindustry:core:$mindustryVersion")
//implementation("com.github.mnemotechnician:mkui:31") todo: do i need mkui?
implementation(files("lib/Autoupdate-lib.jar"))
}
task("jarAndroid") {
dependsOn("jar")
doLast {
val sdkRoot = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT")
if(sdkRoot == null || sdkRoot.isEmpty() || !File(sdkRoot).exists()) {
throw GradleException("""
No valid Android SDK found. Ensure that ANDROID_HOME is set to your Android SDK directory.
Note: if the gradle daemon has been started before ANDROID_HOME env variable was defined, it won't be able to read this variable.
In this case you have to run "./gradlew stop" and try again
""".trimIndent());
}
println("searching for an android sdk... ")
val platformRoot = File("$sdkRoot/platforms/").walkTopDown().findLast {
val fi = File(it, "android.jar")
if (fi.exists()) {
print(it)
println(" — OK.")
}
fi.exists()
}
if (platformRoot == null) throw GradleException("No android.jar found. Ensure that you have an Android platform installed. (platformRoot = $platformRoot)")
//collect dependencies needed to translate java 8+ bytecode code to android-compatible bytecode (yeah, android's dvm and art do be sucking)
val dependencies = (configurations.compileClasspath.files + configurations.runtimeClasspath.files + File(platformRoot, "android.jar")).map { it.path }
val dependenciesStr = Array<String>(dependencies.size * 2) {
if (it % 2 == 0) "--classpath" else dependencies.elementAt(it / 2)
}
//dexing. As a result of this process, a .dex file will be added to the jar file. This requires d8 tool in your $PATH
exec {
workingDir("$buildDir/libs")
commandLine("d8", *dependenciesStr, "--min-api", "14", "--output", "${jarName}-android.jar", "${jarName}-desktop.jar")
}
}
}
task<Jar>("release") {
dependsOn("jarAndroid")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveFileName.set("${jarName}-any-platform.jar")
from(
zipTree("$buildDir/libs/${jarName}-desktop.jar"),
zipTree("$buildDir/libs/${jarName}-android.jar")
)
doLast {
delete { delete("$buildDir/libs/${jarName}-desktop.jar") }
delete { delete("$buildDir/libs/${jarName}-android.jar") }
}
}
tasks.jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveFileName.set("${jarName}-desktop.jar")
from(*configurations.runtimeClasspath.files.map { if (it.isDirectory()) it else zipTree(it) }.toTypedArray())
from(rootDir) {
include("mod.hjson")
include("icon.png")
}
from("assets/") {
include("**")
}
}