Description
openedon Oct 30, 2024
Summary
Mangled names for internal functions are incorrect when the class is present in an Android application or library module. Specifically, Resolver.getJvmName
is returning a name that does not match what the Kotlin compiler generated.
Looks like there's already a downstream issue in Dagger: google/dagger#4493
Environment
KSP: 2.1.0-Beta2-1.0.26 with KSP2
Kotlin: 2.1.0-Beta2
AGP: 8.7.1
Gradle: 8.10
Context
Consider the following code for an Android Library module :library
:
package dev.jonamireh
class TestClass {
internal fun mangled() {
}
}
The actual generated JVM method name for mangled
is mangled$library
even though the Kotlin compiler generated mangled$library_debug
JVM Modules
For the same code in a Kotlin JVM module named :jvm
will be correct, with both the Kotlin compiler and KSP generating mangled$jvm
.
Potential Cause
As a part of #1847, an API was added to retrieve the module name for mangled internal members. This PR also changed how the module name is fed to KSP to match what's expected for JVM modules. However, I think the previous version worked for Android modules. Obviously, KSP needs to handle each module type differently
Sample project
Here's a sample project where :processor
will print the JVM name according to getJvmName
for each internal function. You can test out what KSP thinks the mangled should be with:
./gradlew :library:assembleDebug --info --rerun-tasks | grep "\[ksp\]"
You can swap out :library
for :app
or :jvm
to see the result in Android application and Kotlin JVM modules, respectively as well
Activity