Skip to content

Commit 4bf8835

Browse files
committed
Better retrieve android sdk folder.
1 parent aef36a7 commit 4bf8835

File tree

1 file changed

+24
-17
lines changed
  • adventure-editor/src/main/resources/projectTmpl/android

1 file changed

+24
-17
lines changed

adventure-editor/src/main/resources/projectTmpl/android/build.gradle

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,7 @@ tasks.whenTaskAdded { packageTask ->
135135
}
136136

137137
task run(type: Exec) {
138-
def path
139-
def localProperties = project.file("../local.properties")
140-
if (localProperties.exists()) {
141-
Properties properties = new Properties()
142-
localProperties.withInputStream { instr ->
143-
properties.load(instr)
144-
}
145-
def sdkDir = properties.getProperty('sdk.dir')
146-
if (sdkDir) {
147-
path = sdkDir
148-
} else {
149-
path = "$System.env.ANDROID_HOME"
150-
}
151-
} else {
152-
path = "$System.env.ANDROID_HOME"
153-
}
138+
def path = getSdkFolder()
154139

155140
def adb = path + "/platform-tools/adb"
156141
commandLine "$adb", 'shell', 'am', 'start', '-n', android.defaultConfig.applicationId + '/' + 'com.bladecoder.engine.AndroidLauncher'
@@ -179,9 +164,30 @@ tasks.whenTaskAdded { task ->
179164
}
180165
}
181166

167+
String getSdkFolder() {
168+
def path
169+
def localProperties = project.file("../local.properties")
170+
if (localProperties.exists()) {
171+
Properties properties = new Properties()
172+
localProperties.withInputStream { instr ->
173+
properties.load(instr)
174+
}
175+
def sdkDir = properties.getProperty('sdk.dir')
176+
if (sdkDir) {
177+
path = sdkDir
178+
} else {
179+
path = "$System.env.ANDROID_HOME"
180+
}
181+
} else {
182+
path = "$System.env.ANDROID_HOME"
183+
}
184+
185+
return path
186+
}
187+
182188
String highestSdkAvailable(String defaultSdk) {
183189
try {
184-
def buildToolsDir = new File(android.getSdkDirectory().toString(), "platforms")
190+
def buildToolsDir = new File(getSdkFolder(), "platforms")
185191
def sdks = buildToolsDir.list([accept:{ d, f-> f.startsWith("android-") && new File(d, f).isDirectory() }] as FilenameFilter).sort { a, b -> b <=> a }
186192
def highestSdk = sdks[0]
187193
if (highestSdk != null) {
@@ -198,3 +204,4 @@ String highestSdkAvailable(String defaultSdk) {
198204
defaultSdk
199205
}
200206
}
207+

0 commit comments

Comments
 (0)