Skip to content

[KSP2] Mangled names for internal functions are incorrect for Android modules #2180

Closed

Description

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions