CB-7512: Read android target from project.properties if possible

This commit is contained in:
Ian Clelland 2014-09-10 11:39:29 -04:00
parent c8bbdb23de
commit 0e78dc35d8

View File

@ -17,40 +17,16 @@
under the License. under the License.
*/ */
int[] getAvailableSdks() { import java.util.regex.Pattern
def availableSdks = new ByteArrayOutputStream()
exec {
commandLine 'android', 'list', 'target', '--compact'
standardOutput = availableSdks
}
availableSdks
.toString()
.tokenize('\n')
.findAll { it ==~ /android-(\d+).*/ }
.collect { (it =~ /android-(\d+).*/)[0][1].toInteger() }
.sort( { a, b -> b <=> a } )
}
int highestSdkAvailable(int minSdkVersion) { String getProjectTarget(String defaultTarget) {
def availableSdks def manifestFile = file("project.properties")
try { def pattern = Pattern.compile("target\\s*=\\s*(.*)")
availableSdks = getAvailableSdks() def matcher = pattern.matcher(manifestFile.getText())
} catch (e) { if (matcher.find()) {
println "An exception occurred while trying to find the Android SDK." matcher.group(1)
throw e
}
if (availableSdks.length > 0) {
def highestSdk = availableSdks[0]
if (highestSdk < minSdkVersion) {
throw new RuntimeException(
"No usable Android SDK found. Highest installed version is " +
highestSdk + "; minimum version required is " + minSdkVersion + ".")
}
highestSdk
} else { } else {
throw new RuntimeException( defaultTarget
"No installed SDKs found. Please install the Android SDK version " +
minSdkVersion + " or higher.")
} }
} }
@ -142,6 +118,6 @@ String getAndroidSdkDir() {
androidSdkDir androidSdkDir
} }
cordovaSdkVersion = highestSdkAvailable(19) cordovaSdkVersion = getProjectTarget("android-19")
cordovaBuildToolsVersion = latestBuildToolsAvailable("19.0.0") cordovaBuildToolsVersion = latestBuildToolsAvailable("19.0.0")