Skip to content

Commit e8dfb71

Browse files
committed
build(app): pass Kotlin classes compiled by AGP to the metadata generator
With built-in Kotlin, AGP writes the Kotlin classes to intermediates/built_in_kotlinc/<buildType>/<compile task>/classes rather than KGP's tmp/kotlin-classes/<buildType>. buildMetadata only scanned the latter, so app and plugin Kotlin classes were missing from the metadata and 31 Kotlin specs in the test app failed. Both locations are scanned, so a project module still built by KGP keeps working.
1 parent 4fd2e6e commit e8dfb71

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎test-app/app/build.gradle‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,11 @@ task buildMetadata(type: BuildToolTask) {
833833
inputs.dir(kotlinClassesDir)
834834
}
835835

836+
def builtInKotlinClassesDir = layout.buildDirectory.dir("intermediates/built_in_kotlinc").get().asFile
837+
if (builtInKotlinClassesDir.exists()) {
838+
inputs.dir(builtInKotlinClassesDir)
839+
}
840+
836841
outputs.files("$METADATA_OUT_PATH/treeNodeStream.dat", "$METADATA_OUT_PATH/treeStringsStream.dat", "$METADATA_OUT_PATH/treeValueStream.dat")
837842

838843
workingDir "$BUILD_TOOLS_PATH"
@@ -848,6 +853,7 @@ task buildMetadata(type: BuildToolTask) {
848853

849854
def classesSubDirs = []
850855
def kotlinClassesSubDirs = []
856+
def builtInKotlinClassesDirs = []
851857

852858
subprojectBuildDirectories.each { buildDirectory ->
853859

@@ -871,6 +877,15 @@ task buildMetadata(type: BuildToolTask) {
871877
}
872878
}
873879
}
880+
881+
// Kotlin compiled by AGP itself lands in <buildType>/<compile task>/classes.
882+
def builtInKotlinBuildTypeDir = buildDirectory.dir("intermediates/built_in_kotlinc/$selectedBuildType").get().asFile
883+
builtInKotlinBuildTypeDir.listFiles()?.each { compileTaskDir ->
884+
def compiledClassesDir = new File(compileTaskDir, "classes")
885+
if (compiledClassesDir.isDirectory()) {
886+
builtInKotlinClassesDirs.add(compiledClassesDir)
887+
}
888+
}
874889
}
875890

876891
def generatedClasses = new LinkedList<String>()
@@ -886,6 +901,10 @@ task buildMetadata(type: BuildToolTask) {
886901
}
887902
}
888903

904+
for (File compiledKotlinDir : builtInKotlinClassesDirs) {
905+
generatedClasses.add(compiledKotlinDir.getAbsolutePath())
906+
}
907+
889908
def store = new ArrayList<File>()
890909
for (String dir : generatedClasses) {
891910
listf(dir, store)

0 commit comments

Comments
 (0)