Search code examples
kotlinkotlin-multiplatform

My RELEASE framework file is bigger than DEBUG framework


I have a kotlin multi-platform project for which I am creating a release framework. My release framework is bigger than the debug framework.

Following is the gradle task to create the framework:

task packForXcode(type: Sync) {

    final File frameworkDir = new File(buildDir, "xcode-frameworks")
    final String mode = 'RELEASE'
    final def framework = kotlin.targets.iosArm64.binaries.getFramework(frameworkName, mode)

    inputs.property "mode", mode
    dependsOn framework.linkTask

    from { framework.outputFile.parentFile }
    into frameworkDir

    doLast {
        new File(frameworkDir, 'gradlew').with {
            text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n"
            setExecutable(true)
        }
    }
}

The framework file generated when mode = 'RELEASE' is 5.3 kb but when mode = 'DEBUG' one is 3.8 Kb.

I have 2 questions:

  • Is this expected ?
  • How can reduce or remove unused code while creating such a framework like R8/pro-guard in android ?

Solution

  • This result can be expected, as only release frameworks are embedding bitcode, debug ones have only bitcode markers(see some details here).
    Unused code should be already removed by the compiler, so there is no need to apply other tools here.