Skip to content

Commit 5b16e19

Browse files
committed
fix: resolve SDK platform dir for minor-versioned platforms (android-37.0)
Starting with the API 36.1 scheme, the SDK can ship platforms only in minor-versioned directories (e.g. android-37.0) with no plain android-37 alias, so paths built as "platforms/" + android.compileSdkVersion break the SBG classpath and the typings include filter with a FileNotFoundException on android.jar. Resolve the real platform directory against disk instead: exact match first, else the highest android-N.M for the API level (extension dirs like android-33-ext4 are not base platforms), with a clear error when no platform is installed. Resolution happens at execution time so a missing platform fails the SBG/typings task rather than configuration.
1 parent 6ebb265 commit 5b16e19

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

test-app/app/build.gradle

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,14 +664,53 @@ task 'extractAllJars' {
664664
}
665665
}
666666

667+
// Since API 36.1 the SDK can ship platforms only in minor-versioned directories
668+
// (e.g. android-37.0) with no plain android-37 alias, so the directory name can't be
669+
// derived from android.compileSdkVersion alone — it has to be resolved against disk.
670+
def resolveCompileSdkPlatformName(File sdkDirectory, String compileSdkVersion) {
671+
def platformsDir = new File(sdkDirectory, "platforms")
672+
if (new File(platformsDir, compileSdkVersion).isDirectory()) {
673+
return compileSdkVersion
674+
}
675+
676+
def baseMatch = compileSdkVersion =~ /^android-(\d+)$/
677+
if (baseMatch.matches()) {
678+
def apiLevel = baseMatch.group(1)
679+
def bestName = null
680+
def bestMinor = -1
681+
platformsDir.listFiles()?.each { dir ->
682+
if (!dir.isDirectory()) {
683+
return
684+
}
685+
// Strict android-N.M only — extension dirs like android-33-ext4 are not base platforms
686+
def minorMatch = dir.name =~ /^android-(\d+)\.(\d+)$/
687+
if (minorMatch.matches() && minorMatch.group(1) == apiLevel) {
688+
def minor = minorMatch.group(2) as int
689+
if (minor > bestMinor) {
690+
bestMinor = minor
691+
bestName = dir.name
692+
}
693+
}
694+
}
695+
if (bestName != null) {
696+
return bestName
697+
}
698+
}
699+
700+
throw new GradleException("No Android SDK platform directory found for ${compileSdkVersion} in ${platformsDir}. " +
701+
"Install the matching SDK Platform with the Android SDK Manager.")
702+
}
703+
667704
task 'collectAllJars' {
668705
dependsOn extractAllJars
669706
description "gathers all paths to jar dependencies before building metadata with them"
670707

671708
def sdkPath = android.sdkDirectory.getAbsolutePath()
672-
def androidJar = sdkPath + "/platforms/" + android.compileSdkVersion + "/android.jar"
673709

674710
doFirst {
711+
def platformName = resolveCompileSdkPlatformName(android.sdkDirectory, android.compileSdkVersion)
712+
def androidJar = sdkPath + "/platforms/" + platformName + "/android.jar"
713+
675714
def allJarPaths = new LinkedList<String>()
676715
allJarPaths.add(androidJar)
677716
allJarPaths.addAll(pluginsJarLibraries)
@@ -1042,12 +1081,13 @@ task generateTypescriptDefinitions(type: BuildToolTask) {
10421081
}
10431082

10441083
def paramz = new ArrayList<String>()
1045-
def includeDirs = ["com.android.support", "/platforms/" + android.compileSdkVersion]
10461084

10471085
workingDir "$BUILD_TOOLS_PATH"
10481086
mainClass = "-jar"
10491087

10501088
doFirst {
1089+
def includeDirs = ["com.android.support", "/platforms/" + resolveCompileSdkPlatformName(android.sdkDirectory, android.compileSdkVersion)]
1090+
10511091
delete "$TYPINGS_PATH"
10521092

10531093
// Resolved against the project when building from source; an empty rootPath leaves it

0 commit comments

Comments
 (0)