logback-android icon indicating copy to clipboard operation
logback-android copied to clipboard

"Failed to instantiate converter class" & %PARSER_ERROR due to R8

Open gmk57 opened this issue 3 years ago • 0 comments

Description

Since AGP 7.0 its shrinker (R8) in release build type works more aggressively and strips no-arg constructors from logback's pattern converters.

Symptoms

  1. StatusPrinter prints configuration error messages like this:
|-ERROR in u1.a@10edaa7 - Failed to instantiate converter class [a1.e] for keyword [msg] c2.f: Failed to instantiate type a1.e
	at c2.f: Failed to instantiate type a1.e
    at androidx.savedstate.d.m(SourceFile:1)
    at u1.a.J(SourceFile:19)
    at t1.g.start(SourceFile:10)
    at w0.a.start(SourceFile:5)
    at f3.a.<init>(SourceFile:33)
    at gmk57.testlogback.App.onCreate(SourceFile:2)
    at ...
Caused by: java.lang.NoSuchMethodException: <init> []
    at java.lang.Class.getConstructor0(Class.java:2204)
    at ...
|-ERROR in u1.a@10edaa7 - [msg] is not a valid conversion word

a1.e is an obfuscated ch.qos.logback.classic.pattern.ContextNameConverter Same happens with DateConverter, FileOfCallerConverter, etc

  1. Log file, instead of real log lines, consists of repeated: %PARSER_ERROR[d] %PARSER_ERROR[level] %PARSER_ERROR[msg]%PARSER_ERROR[n]

Steps to reproduce

  1. Add logback-android to project, configure it in code, e.g. with AsyncAppender, RollingFileAppender & PatternLayoutEncoder (I can provide a specific configuration, but don't think it matters much).
  2. Build app in release mode with minification. For some reason I couldn't reproduce the issue in debug mode with minifyEnabled true.

Fix

Add to proguard-rules.pro: -keepclassmembers class ch.qos.logback.classic.pattern.* { <init>(); } Ideally this should be added to library's consumer-rules.pro.

Environment

  • logback-android version: 2.0.0
  • Android version: does not matter

gmk57 avatar Sep 13 '21 09:09 gmk57