kotlin-logging icon indicating copy to clipboard operation
kotlin-logging copied to clipboard

Cannot process releases newer than 7.0.0 with Proguard

Open sproctor opened this issue 8 months ago • 8 comments

7.0.0 is working fine. When trying to upgrade, building with proguard produces the following error:

error[1004]: proguard.evaluation.exception.IncompleteClassHierarchyException
  --> io/github/oshai/kotlinlogging/logback/internal/LogbackLoggerWrapper : at(Lio/github/oshai/kotlinlogging/Level;Lio/github/oshai/kotlinlogging/Marker;Lkotlin/jvm/functions/Function1;)V at return
207 |     dup
208 |     astore v4
210 |     getfield #23
213 |     aload_1 v1
214 |     checkcast #125
217 |     invokevirtual #129
220 |     return
  |     ^^^^^^ Can't find common super class of [io.github.oshai.kotlinlogging.Level] (with 3 known super classes: java.lang.Enum, java.lang.Object, io.github.oshai.kotlinlogging.Level) and [io.github.oshai.kotlinlogging.logback.internal.LogbackLogEvent] (with 1 known super classes: io.github.oshai.kotlinlogging.logback.internal.LogbackLogEvent and 1 unknown classes: ch.qos.logback.classic.spi.LoggingEvent)
221 |     iconst_1
Variables: [P0:P0:Lio/github/oshai/kotlinlogging/logback/internal/LogbackLoggerWrapper;=!][P1:P1:Lio/github/oshai/kotlinlogging/Level;=][P2:P2:Lio/github/oshai/kotlinlogging/Marker;][P3:P3:Lkotlin/jvm/functions/Function1;][31:P0:Lio/github/oshai/kotlinlogging/logback/internal/LogbackLoggerWrapper;=!][17:P1:Lio/github/oshai/kotlinlogging/Level;=][15:P2:Lio/github/oshai/kotlinlogging/Marker;]
Stack: 

proguard.evaluation.exception.IncompleteClassHierarchyException: Can't find common super class of [io.github.oshai.kotlinlogging.Level] (with 3 known super classes: java.lang.Enum, java.lang.Object, io.github.oshai.kotlinlogging.Level) and [io.github.oshai.kotlinlogging.logback.internal.LogbackLogEvent] (with 1 known super classes: io.github.oshai.kotlinlogging.logback.internal.LogbackLogEvent and 1 unknown classes: ch.qos.logback.classic.spi.LoggingEvent)
	at proguard.evaluation.value.TypedReferenceValue.findCommonClass(TypedReferenceValue.java:532) ~[proguard-core-9.1.6.jar:9.1.6]
	at proguard.evaluation.value.TypedReferenceValue.generalize(TypedReferenceValue.java:296) ~[proguard-core-9.1.6.jar:9.1.6]
	at proguard.evaluation.value.TypedReferenceValue.generalize(TypedReferenceValue.java:217) ~[proguard-core-9.1.6.jar:9.1.6]
	at proguard.evaluation.value.TracedReferenceValue.generalize(TracedReferenceValue.java:197) ~[proguard-core-9.1.6.jar:9.1.6]
	at proguard.evaluation.value.TracedReferenceValue.generalize(TracedReferenceValue.java:115) ~[proguard-core-9.1.6.jar:9.1.6]
	at proguard.evaluation.value.ReferenceValue.generalize(ReferenceValue.java:317) ~[proguard-core-9.1.6.jar:9.1.6]
	at proguard.evaluation.Variables.generalize(Variables.java:120) ~[proguard-core-9.1.6.jar:9.1.6]
	at proguard.evaluation.TracedVariables.generalize(TracedVariables.java:92) ~[proguard-core-9.1.6.jar:9.1.6]
	at proguard.evaluation.PartialEvaluator.evaluateSingleInstructionBlock(PartialEvaluator.java:703) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.evaluation.PartialEvaluator.evaluateInstructionBlock(PartialEvaluator.java:624) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.evaluation.PartialEvaluator.evaluateInstructionBlockAndExceptionHandlers(PartialEvaluator.java:599) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.evaluation.PartialEvaluator.visitCodeAttribute0(PartialEvaluator.java:399) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.evaluation.PartialEvaluator.visitCodeAttribute(PartialEvaluator.java:347) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.preverify.CodePreverifier.visitCodeAttribute0(CodePreverifier.java:109) [proguard-core-9.1.6.jar:7.6.0]
	at proguard.preverify.CodePreverifier.visitCodeAttribute(CodePreverifier.java:82) [proguard-core-9.1.6.jar:7.6.0]
	at proguard.classfile.attribute.CodeAttribute.accept(CodeAttribute.java:105) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.classfile.ProgramMethod.attributesAccept(ProgramMethod.java:118) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.classfile.attribute.visitor.AllAttributeVisitor.visitProgramMember(AllAttributeVisitor.java:77) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.classfile.visitor.MemberVisitor.visitProgramMethod(MemberVisitor.java:47) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.classfile.ProgramMethod.accept(ProgramMethod.java:113) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.classfile.ProgramClass.methodsAccept(ProgramClass.java:589) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.classfile.visitor.AllMethodVisitor.visitAnyClass(AllMethodVisitor.java:39) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.classfile.visitor.ClassVisitor.visitProgramClass(ClassVisitor.java:35) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.classfile.visitor.ClassVersionFilter.visitProgramClass(ClassVersionFilter.java:69) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.classfile.ProgramClass.accept(ProgramClass.java:491) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.classfile.ClassPool.classesAccept(ClassPool.java:218) [proguard-core-9.1.6.jar:9.1.6]
	at proguard.preverify.Preverifier.execute(Preverifier.java:65) [proguard-base-7.6.0.jar:7.6.0]
	at proguard.pass.PassRunner.run(PassRunner.java:24) [proguard-base-7.6.0.jar:7.6.0]
	at proguard.ProGuard.preverify(ProGuard.java:555) [proguard-base-7.6.0.jar:7.6.0]
	at proguard.ProGuard.execute(ProGuard.java:232) [proguard-base-7.6.0.jar:7.6.0]
	at proguard.ProGuard.main(ProGuard.java:648) [proguard-base-7.6.0.jar:7.6.0]

sproctor avatar Apr 11 '25 21:04 sproctor

Thank you for reporting an issue. See the wiki for documentation and slack for questions.

github-actions[bot] avatar Apr 11 '25 21:04 github-actions[bot]

It look like a dependency on logback which is implicit (added for #452). Can you try a workaround of adding logback as compile only dependency?

Another option is to tell proguard that this class is not actually reachable / used at runtime: io/github/oshai/kotlinlogging/logback/internal/LogbackLoggerWrapper.

oshai avatar Apr 15 '25 07:04 oshai

I couldn't figure out how to work around it with proguard. adding an implementation worked, compileOnly did not.

sproctor avatar Apr 17 '25 23:04 sproctor

I don't see any way to specify that a class is not used with proguard. Including the dependency caused SLF4J to report an error for having 2 providers. Disabling proguard optimizations works. I think the ideal would be to have the logback stuff in a separate package.

sproctor avatar Jun 10 '25 12:06 sproctor

Having separate sub projects structure makes it complicated with KMP, so I prefer finding an alternative.

oshai avatar Jun 18 '25 11:06 oshai