-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle
74 lines (59 loc) · 2.66 KB
/
build.gradle
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
plugins {
id 'java'
}
group pGroup
sourceSets.main {
java.srcDir("src/")
resources.srcDir("assets/")
}
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}
dependencies {
implementation "com.github.Anuken.Mindustry:core:$pMindustryVersion"
}
jar {
archiveFileName.set pArtifactFilename
}
task dexify(type: Jar) {
archiveName "dexed-$pArtifactFilename"
final File jarArtifact = new File(tasks.jar.archiveFile.get().asFile.parent, pArtifactFilename),
dexedArtifact = new File(tasks.dexify.getTemporaryDir(), "dexed.jar")
doFirst {
exec {
workingDir dexedArtifact.parent
// Get Android SDK paths and validate
String androidSdk = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT")
if (!(androidSdk && new File(androidSdk).exists())) {
throw new GradleException("Set ANDROID_HOME or ANDROID_SDK_ROOT environment variables to a valid Android SDK.")
}
File platforms = new File(androidSdk, "platforms/")
if (!(platforms.exists() && platforms.isDirectory())) {
throw new GradleException("Could not find directory '${platforms.getAbsolutePath()}'." +
" Ensure an Android SDK is installed.")
}
File androidJar = new File(project.hasProperty("pAndroidSdkVersion") ?
new File(platforms, project.property("pAndroidSdkVersion") as String) :
platforms.listFiles().reverse().find
{ it.isDirectory() && new File(it, "android.jar").exists() },
"android.jar")
if (!(androidJar && androidJar.exists())) {
throw new GradleException("Could not find 'android.jar' in '${platforms.getAbsolutePath()}'." +
" If there is, specify valid 'pAndroidSdkVersion' in 'gradle.properties'")
}
// Assemble d8 invocation
List<File> files = configurations.compileClasspath.asList() + configurations.runtimeClasspath.asList() + [androidJar]
List<String> command = ["d8", "--min-api", pMinApi,
*files.collect { ["--classpath", it.path] }.flatten(),
"--output", dexedArtifact, jarArtifact]
// Awaken d8
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows'))
commandLine("cmd", "/c", *command)
else
commandLine(*command)
}
}
from(zipTree(jarArtifact), zipTree(dexedArtifact))
}
task buildDex dependsOn "build", "dexify"