Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support kotlin multiplatform modules #20

Merged
merged 3 commits into from
Feb 19, 2025
Merged

Conversation

0xera
Copy link
Contributor

@0xera 0xera commented Jan 25, 2025

closes #13

@@ -158,6 +162,9 @@ internal class DefaultVariantExtractor @Inject constructor(
)

project.isJava || project.isKotlinJvm -> JarAppSizeVariant(project)

project.isKotlinMultiplatform -> JarAppSizeVariant(project, "jvmJar", "jvmRuntimeClasspath")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that a KMP module could be both a jvmJar and an Android module at the same time. (Provide a jar file & aar file)
It's broken the current SizerVariant; let me update the API to support this feature.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already work on this issue, let me share the MR later

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The KMP module requires the android-library plugin to be included if an Android target is specified. Therefore, the Android AppSizeVariant already includes all sources when building AAR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. interesting, the AAR file contains the module's JVM classes as well
Earlier, I saw the kmp-module has jar & aar files simultaneously if we have both JVM & android config. I did not check the binary content.

Screenshot 2025-02-14 at 10 57 29 AM

Then it should work. Let me review the MR properly later

@@ -275,17 +282,19 @@ internal class DefaultVariantExtractor @Inject constructor(
}

internal class JarAppSizeVariant(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal const val KMP_JAR_TASK = "jvmJar"
internal const val KMP_RUNTIME_CONFIGURATION = "jvmRuntimeClasspath"

Let's have a separate class for KMP.

internal class KmpSizerVariant(
    private val project: Project
) : SizerVariant {
    override val binaryOutPut: File
        get() {
            val jarTask = project.tasks.findByName(KMP_JAR_TASK) as Jar
            return jarTask.archiveFile.get().asFile
        }

    override val runtimeConfiguration: Configuration by lazy {
        project.configurations.first {
            it.name.equals(KMP_RUNTIME_CONFIGURATION, true)
        }
    }

    override val buildType: String
        get() = ""
    override val buildFlavor: String
        get() = ""
}

@@ -73,6 +74,13 @@ internal class DefaultArchiveExtractor @Inject constructor(
)
}

project.isKotlinMultiplatform -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can merge with the other two

            project.isKotlinJvm || project.isJava || project.isKotlinMultiplatform -> {
                return JavaModuleDependency(
                    name = project.pathTrimColon,
                    pathToArtifact = matchVariant.binaryOutPut.path
                )
            }

}

project.isKotlinMultiplatform -> {
task.dependsOn(project.tasks.named("jvmJar"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you help to merge

internal const val KMP_JAR_TASK = "jvmJar"
...
            project.isKotlinMultiplatform -> {
                task.dependsOn(project.tasks.named(KMP_JAR_TASK))
            }

            project.isKotlinJvm || project.isJava -> {
                task.dependsOn(project.tasks.named(JavaPlugin.JAR_TASK_NAME))
            }

@akshay-grabtaxi akshay-grabtaxi merged commit 2dc7b63 into grab:master Feb 19, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support kotlin multiplatform modules
3 participants