Skip to content

Commit ef4e29a

Browse files
committed
Resolve Picocli InitializationException in release builds
R8 minification was aggressively stripping Picocli annotations (@command, @option) and renaming command classes, causing reflection to fail at runtime. We add targeted ProGuard rules to ensure CLI stability: - Preserved attributes required for reflection and annotations. - Protected any class or member annotated with Picocli markers. - Kept internal Picocli classes required for standard help mixins. - Retained Gson IPC data models (CliRequest/Response) to prevent socket serialization failures in release builds.
1 parent e267e15 commit ef4e29a

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

daemon/proguard-rules.pro

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,29 @@
77
-keepclasseswithmembers class org.matrix.vector.daemon.Cli {
88
public static void main(java.lang.String[]);
99
}
10-
-keep class org.matrix.vector.daemon.Cli { *; }
11-
-keep class org.matrix.vector.daemon.Cli$Companion { *; }
12-
-keep class org.matrix.vector.daemon.*Command { *; }
10+
11+
12+
# Keep IPC data models intact so Gson serializes the correct JSON keys
1313
-keep class org.matrix.vector.daemon.CliRequest { *; }
1414
-keep class org.matrix.vector.daemon.CliResponse { *; }
1515

16+
# Preserve annotations, generic signatures, and inner classes (critical for picocli reflection)
17+
-keepattributes *Annotation*, Signature, InnerClasses, EnclosingMethod
18+
19+
# Keep internal Picocli classes required for `mixinStandardHelpOptions = true`
1620
-keep class picocli.CommandLine$AutoHelpMixin { *; }
1721
-keep class picocli.CommandLine$HelpCommand { *; }
18-
-keep @picocli.CommandLine$Command class picocli.** { *; }
1922

20-
# MUST keep annotations for Picocli to function via reflection
21-
-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod
23+
# Keep ANY class (and its constructor) annotated with @Command
24+
-keep @picocli.CommandLine$Command class * {
25+
<init>(...);
26+
}
27+
28+
# Keep ANY field/method using a Picocli annotation (@Option, @Parameters, etc.)
29+
-keepclassmembers class * {
30+
@picocli.CommandLine$* *;
31+
}
32+
2233

2334
-keepclasseswithmembers class org.matrix.vector.daemon.env.LogcatMonitor {
2435
private int refreshFd(boolean);

0 commit comments

Comments
 (0)