-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Compilation fails with ~200 items in strings.xml (MethodTooLargeException) #4194
Comments
The same problem occurs if we use a huge icon pack. This pack is for example. |
Fixed for me, thanks! @tipapro I'm closing the issue since it was specific to strings. I think you should open another one if the problem persists for your use case. |
Hello @terrakok, the error is back on exception: exception: java.lang.RuntimeException: Error generating class file components/resources/demo/shared/generated/resources/String0.class (compiled from [/Users/azef/dev/kotlin/playground/compose-multiplatform/components/resources/demo/shared/build/generated/compose/resourceGenerator/kotlin/components/resources/demo/shared/generated/resources/String0.kt]): Method too large: components/resources/demo/shared/generated/resources/String0.<clinit> ()V
exception: at org.jetbrains.kotlin.codegen.ClassFileFactory$OutputClassFile.asByteArray(ClassFileFactory.java:310)
exception: at org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAll(outputUtils.kt:33)
exception: at org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAllTo(outputUtils.kt:47)
exception: at org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAll(outputUtils.kt:52)
exception: at org.jetbrains.kotlin.cli.jvm.compiler.CliCompilerUtilsKt.writeOutput(cliCompilerUtils.kt:134)
exception: at org.jetbrains.kotlin.cli.jvm.compiler.CliCompilerUtilsKt$createOutputFilesFlushingCallbackIfPossible$1.invoke(cliCompilerUtils.kt:95)
exception: at org.jetbrains.kotlin.cli.jvm.compiler.CliCompilerUtilsKt$createOutputFilesFlushingCallbackIfPossible$1.invoke(cliCompilerUtils.kt:93)
exception: at org.jetbrains.kotlin.codegen.state.GenerationStateKt$GenerationStateEventCallback$1.invoke(GenerationState.kt:412)
exception: at org.jetbrains.kotlin.codegen.state.GenerationStateKt$GenerationStateEventCallback$1.invoke(GenerationState.kt:411)
exception: at org.jetbrains.kotlin.codegen.state.GenerationState.afterIndependentPart(GenerationState.kt:363)
exception: at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.invokeCodegen(JvmIrCodegenFactory.kt:366)
exception: at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.runCodegen(KotlinToJVMBytecodeCompiler.kt:347)
exception: at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:122)
exception: at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:43)
exception: at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:165)
exception: at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:50)
exception: at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:104)
exception: at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:48)
exception: at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
exception: at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:79)
exception: at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:43)
exception: at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit(CLITool.kt:180)
exception: at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit$default(CLITool.kt:175)
exception: at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMain(CLITool.kt:167)
exception: at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler$Companion.main(K2JVMCompiler.kt:250)
exception: at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.main(K2JVMCompiler.kt)
exception: caused by: org.jetbrains.org.objectweb.asm.MethodTooLargeException: Method too large: components/resources/demo/shared/generated/resources/String0.<clinit> ()V
exception: at org.jetbrains.org.objectweb.asm.MethodWriter.computeMethodInfoSize(MethodWriter.java:2087)
exception: at org.jetbrains.org.objectweb.asm.ClassWriter.toByteArray(ClassWriter.java:489)
exception: at org.jetbrains.kotlin.codegen.ClassBuilderFactories$2.asBytes(ClassBuilderFactories.java:118)
exception: at org.jetbrains.kotlin.codegen.DelegatingClassBuilderFactory.asBytes(DelegatingClassBuilderFactory.kt:36)
exception: at org.jetbrains.kotlin.codegen.DelegatingClassBuilderFactory.asBytes(DelegatingClassBuilderFactory.kt:36)
exception: at org.jetbrains.kotlin.codegen.ClassFileFactory$ClassBuilderAndSourceFileList.asBytes(ClassFileFactory.java:343)
exception: at org.jetbrains.kotlin.codegen.ClassFileFactory$OutputClassFile.asByteArray(ClassFileFactory.java:307)
exception: ... 25 more
exception: |
I had a similar issue with RC version of compose 1.6.0. The Res file failed to be generated when adding exactly 2048 strings. with 2047 the file was generated. The 2048 strings could be placed in one localization or the combined total of multiple localisations. After upgrading to final 1.6.0 this issue was gone. |
@terrakok I did a git pull on the compose repo, updated the gradle properties file with 1.6.0, and did the same repro steps as above. I'll see if the test fails on my end. |
@terrakok We can make the test fail if we add back qualifiers into the mix. You can replace import java.util.Locale
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
}
group = "app.group"
kotlin {
jvm("desktop")
sourceSets {
commonMain {
dependencies {
implementation(compose.runtime)
implementation(compose.material)
implementation(compose.components.resources)
}
}
}
}
val generateResourceFiles = tasks.register("generateResourceFiles") {
val resourcesFolder = project.file("src/commonMain/composeResources")
val count = 25_000
val numberOfLanguages = 5
val langs = Locale.getAvailableLocales()
.map { it.language }
.filter { it.count() == 2 }
.sorted()
.distinct()
.take(numberOfLanguages)
.toList()
doLast {
langs.forEachIndexed { langIndex, lang ->
val txt = buildString {
appendLine("<resources>")
repeat(count) {
appendLine(" <string name=\"str_${it}\">str_${it}</string>")
}
appendLine("</resources>")
}
val fileName = if (langIndex == 0) {
"values/strings.xml"
} else {
"values-$lang/strings.xml"
}
File(resourcesFolder, fileName).apply {
parentFile.mkdirs()
writeText(txt)
}
}
}
doLast {
repeat(count) {
File(resourcesFolder, "drawable/icon_$it.xml").apply {
parentFile.mkdirs()
createNewFile() //empty file
}
}
}
}
tasks.named("generateComposeResClass") {
dependsOn(generateResourceFiles)
} I tested with |
thank you! will fix it today |
…o avoid MethodTooLargeException More info: #4194
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks. |
Description
I'm not sure what should be considered as a reasonable amount of strings in a
strings.xml
file but, when trying to replace moko-resources in an existing project, it failed to compile with this error:Repro
In order to reproduce it, you can add the following code to
components/resources/demo/shared/build.gradle.kts
generateStringFiles task
It'll create multiple
values-XXX/strings.xml
files, each filled with the requested amount of strings when you run./gradlew :resources:demo:desktopApp:run
.With the default values (200 strings, 15 languages), the
Res.kt
file will have 14k lines.Tested with
compose.version=1.6.0-beta01
Workaround
Maintain different string files in multiple modules.
The text was updated successfully, but these errors were encountered: