@@ -16,6 +16,7 @@ repositories {
16
16
ext {
17
17
mindustryVersion = ' v135'
18
18
jabelVersion = ' 0.6.0'
19
+ sdkRoot = System . getenv(" ANDROID_HOME" ) ?: System . getenv(" ANDROID_SDK_ROOT" )
19
20
}
20
21
21
22
allprojects {
@@ -30,13 +31,58 @@ dependencies {
30
31
annotationProcessor " com.github.Anuken:jabel:$jabelVersion "
31
32
}
32
33
34
+
35
+
33
36
jar {
34
- archiveFileName = " ${ project.archivesBaseName} .jar"
37
+ archiveFileName = " ${ project.archivesBaseName} Desktop .jar"
35
38
from {
36
39
configurations. runtimeClasspath. collect { it. isDirectory() ? it : zipTree(it) }
37
40
}
38
41
39
42
from(rootDir) {
40
43
include " mod.hjson"
41
44
}
45
+ }
46
+
47
+ task jarAndroid {
48
+ dependsOn " jar"
49
+
50
+ doLast {
51
+ if (! sdkRoot || ! new File (sdkRoot). exists()) throw new GradleException (" No valid Android SDK found. Ensure that ANDROID_HOME is set to your Android SDK directory." )
52
+
53
+ def platformRoot = new File (" $sdkRoot /platforms/" ). listFiles(). sort(). reverse(). find { f -> new File (f, " android.jar" ). exists() }
54
+
55
+ if (! platformRoot) throw new GradleException (" No android.jar found. Ensure that you have an Android platform installed." )
56
+
57
+ // collect dependencies needed for desugaring
58
+ def dependencies = (configurations. compileClasspath. asList() + configurations. runtimeClasspath. asList() + [new File (platformRoot, " android.jar" )]). collect { " --classpath $it . path " }. join(" " )
59
+
60
+ // dex and desugar files - this requires d8 in your PATH
61
+ def paras = " $dependencies --min-api 14 --output ${ project.archivesBaseName} Android.jar ${ project.archivesBaseName} Desktop.jar" . toString()
62
+ try {
63
+ " d8 $paras " . execute(null , new File (" $buildDir /libs" )). waitForProcessOutput(System . out, System . err)
64
+ } catch (Exception ignored) {
65
+ logger. lifecycle(" d8 cannot be found in your PATH, so trying to use an absolute path." )
66
+ def cmdOutput = new ByteArrayOutputStream ()
67
+ " where d8" . execute(). waitForProcessOutput(cmdOutput, System . err)
68
+ def d8FullPath = cmdOutput. toString(). replace(" \r " , " " ). replace(" \n " , " " )
69
+ logger. lifecycle(" d8 was found at $d8FullPath " )
70
+ " $d8FullPath $paras " . execute(null , new File (" $buildDir /libs" )). waitForProcessOutput(System . out, System . err)
71
+ }
72
+ }
73
+ }
74
+
75
+ task deploy (type : Jar ) {
76
+ dependsOn jarAndroid
77
+ dependsOn jar
78
+ archiveFileName = " ${ project.archivesBaseName} .jar"
79
+
80
+ from { [zipTree(" $buildDir /libs/${ project.archivesBaseName} Desktop.jar" ), zipTree(" $buildDir /libs/${ project.archivesBaseName} Android.jar" )] }
81
+
82
+ doLast {
83
+ delete {
84
+ delete " $buildDir /libs/${ project.archivesBaseName} Desktop.jar"
85
+ delete " $buildDir /libs/${ project.archivesBaseName} Android.jar"
86
+ }
87
+ }
42
88
}
0 commit comments