|
4 | 4 | -dontnote ** |
5 | 5 | -dontobfuscate |
6 | 6 |
|
| 7 | +# ADFA-3604: R8's optimize pass (inlining/method merging) can silently |
| 8 | +# retarget a call to the wrong method when it fails to parse Kotlin 2.3.0 |
| 9 | +# metadata (see "R8: An error occurred when parsing kotlin metadata" in the |
| 10 | +# build log) -- observed corrupting calls to utils.TestModeUtilsKt.isTestMode |
| 11 | +# into calls to the unrelated, device-missing dalvik.system.VMRuntime.isTestMode, |
| 12 | +# crashing every release build on launch. Shrinking (dead-code removal) is |
| 13 | +# what actually cuts dex size; the optimize passes are the risky part given |
| 14 | +# this R8/Kotlin version mismatch, so disable only optimization. |
| 15 | +-dontoptimize |
| 16 | + |
7 | 17 | -keep class javax.** { *; } |
8 | 18 | -keep class jdkx.** { *; } |
9 | 19 |
|
|
19 | 29 | # Builder model implementations |
20 | 30 | -keep class com.itsaky.androidide.builder.model.** { *; } |
21 | 31 |
|
| 32 | +# lsp/kotlin registers its own IntelliJ project/application services -- some |
| 33 | +# by class name in lsp/kotlin/src/main/resources/META-INF/kt-lsp/kt-lsp.xml, |
| 34 | +# the rest via ::class literals in |
| 35 | +# lsp/kotlin/.../registrar/AnalysisApiServiceProviders.kt, which PicoContainer |
| 36 | +# then instantiates reflectively via each class's no-arg constructor. A |
| 37 | +# ::class literal doesn't count as an actual `new` call to R8, so it kept |
| 38 | +# stripping "unused" no-arg constructors one class at a time as each was |
| 39 | +# discovered on-device (ClassNotFoundException on DirectInheritorsProvider, |
| 40 | +# then a PicoInitializationException on ModuleDependentsProvider's missing |
| 41 | +# constructor). Keep the whole package rather than list every implementation |
| 42 | +# class in AnalysisApiServiceProviders.kt individually. |
| 43 | +-keep class com.itsaky.androidide.lsp.kotlin.compiler.services.** { *; } |
| 44 | + |
| 45 | +# Kotlin Analysis API (bundled in subprojects/kotlin-analysis-api, used by the |
| 46 | +# Kotlin LSP). subprojects/kotlin-analysis-api/consumer-rules.pro keeps every |
| 47 | +# class this jar's own IntelliJ plugin XML descriptors and ServiceLoader |
| 48 | +# entries reference by name, but on-device testing kept surfacing distinct |
| 49 | +# reflection paths that narrow list didn't cover -- not just inside this jar, |
| 50 | +# but in other lsp/kotlin runtime dependencies too (Caffeine picks a cache |
| 51 | +# implementation from dozens of codegenned variant classes at runtime; a |
| 52 | +# protobuf-lite message field is resolved by name string; lsp/kotlin's own |
| 53 | +# kt-lsp.xml above; and a NullPointerException deep in IntelliJ's own |
| 54 | +# JavaCoreApplicationEnvironment bootstrap, verified absent on an unshrunk |
| 55 | +# debug build). Each fix was quick but the next gap kept appearing elsewhere |
| 56 | +# in the same dependency graph, so rather than keep discovering them one |
| 57 | +# on-device crash at a time, keep every runtime dependency lsp/kotlin pulls in |
| 58 | +# whole. This gives up the dex-size reduction for this whole dependency graph; |
| 59 | +# see ADFA-3604 for the size trade-off. |
| 60 | +-keep class org.jetbrains.kotlin.** { *; } |
| 61 | +-keep class com.github.benmanes.caffeine.** { *; } |
| 62 | +-keep class kotlin.reflect.** { *; } |
| 63 | +-keep class kotlin.script.** { *; } |
| 64 | +-keep class kotlinx.coroutines.internal.** { *; } |
| 65 | +-keep class one.util.streamex.** { *; } |
| 66 | +-keep class gnu.trove.** { *; } |
| 67 | + |
22 | 68 | # Eclipse |
23 | 69 | -keep class org.eclipse.** { *; } |
24 | 70 |
|
|
66 | 112 | } |
67 | 113 | -keep class com.itsaky.androidide.utils.DialogUtils { public <methods>; } |
68 | 114 |
|
69 | | -# APK Metadata |
70 | | --keep class com.itsaky.androidide.models.ApkMetadata { *; } |
71 | | --keep class com.itsaky.androidide.models.ArtifactType { *; } |
72 | | --keep class com.itsaky.androidide.models.MetadataElement { *; } |
| 115 | +# Gson model classes deserialized only via reflection (gson.fromJson(..., |
| 116 | +# X::class.java)), same "R8 strips the unreachable constructor" issue as |
| 117 | +# templates.impl.zip below. Covers OpenedFilesCache/OpenedFile (no prior |
| 118 | +# rule) as well as the APK metadata classes already listed individually. |
| 119 | +-keep class com.itsaky.androidide.models.** { *; } |
| 120 | +-keep class com.itsaky.androidide.lsp.debug.model.** { *; } |
73 | 121 |
|
74 | 122 | # Parcelable |
75 | 123 | -keepclassmembers class * implements android.os.Parcelable { |
|
88 | 136 |
|
89 | 137 | -keep class com.itsaky.androidide.treesitter.** { *; } |
90 | 138 |
|
| 139 | +# Protobuf lite: the generated runtime resolves message fields by name via |
| 140 | +# reflection (the info string baked into newMessageInfo()), so shrinking a |
| 141 | +# "field with no direct bytecode reference" breaks it at runtime with a |
| 142 | +# NoSuchFieldException (observed on SyncMetaModels$SyncMeta.projectModelInfo_). |
| 143 | +-keepclassmembers class * extends com.google.protobuf.GeneratedMessageLite { |
| 144 | + <fields>; |
| 145 | +} |
| 146 | + |
91 | 147 | # Retrofit 2 |
92 | 148 | -dontwarn retrofit2.** |
93 | 149 | -keep class retrofit2.** { *; } |
|
101 | 157 | -keep interface okhttp3.** { *; } |
102 | 158 | -dontwarn okhttp3.** |
103 | 159 |
|
104 | | -# Stat uploader |
105 | | --keep class com.itsaky.androidide.stats.** { *; } |
106 | | - |
107 | 160 | # Gson |
108 | 161 | -keep class * extends com.google.gson.TypeAdapter |
109 | 162 | -keep class * implements com.google.gson.TypeAdapterFactory |
110 | 163 | -keep class * implements com.google.gson.JsonSerializer |
111 | 164 | -keep class * implements com.google.gson.JsonDeserializer |
112 | 165 |
|
| 166 | +# Gson model classes: nothing calls `new TemplatesIndex(...)` directly -- |
| 167 | +# only gson.fromJson(..., TemplatesIndex::class.java) does, via reflection. |
| 168 | +# With no traceable constructor call, R8 strips the constructor and Gson's |
| 169 | +# runtime then reports the class as abstract ("Failed to load template |
| 170 | +# archive ... Abstract classes can't be instantiated!"). |
| 171 | +-keep class com.itsaky.androidide.templates.impl.zip.** { *; } |
| 172 | + |
113 | 173 | -keepclassmembers,allowobfuscation class * { |
114 | 174 | @com.google.gson.annotations.SerializedName <fields>; |
115 | 175 | } |
|
143 | 203 | -keep class com.itsaky.androidide.plugins.** { *; } |
144 | 204 | -keep interface com.itsaky.androidide.plugins.** { *; } |
145 | 205 |
|
146 | | -## Initial rules to enable when R8 is shrinking to address exceptions |
147 | | -#-keep class com.sun.tools.jdi.** { *; } |
148 | | -#-keep class com.sun.jdi.** { *; } |
| 206 | +## ADFA-3604: JDI's SocketAttachingConnector/SocketListeningConnector are |
| 207 | +## loaded via ServiceLoader (META-INF/services), which R8 can't trace, so it |
| 208 | +## stripped their no-arg constructors. This surfaced as |
| 209 | +## "ServiceConfigurationError: Provider ... could not be instantiated" -> |
| 210 | +## "java.lang.Error: no Connectors loaded" from VirtualMachineManagerImpl, |
| 211 | +## which the app then reports to the user as a generic "Network access |
| 212 | +## error" (the debug-connect failure handler always appends a network |
| 213 | +## suggestion regardless of cause) even though this has nothing to do with |
| 214 | +## network permissions. This is exactly the exceptions these rules were |
| 215 | +## anticipating -- enabling them now that shrinking is genuinely on. |
| 216 | +-keep class com.sun.tools.jdi.** { *; } |
| 217 | +-keep class com.sun.jdi.** { *; } |
149 | 218 |
|
150 | 219 | ## R8 Kotlin metadata workaround for Kotlin 2.3.0 compatibility |
151 | 220 | ## Suppresses D8 errors when parsing kotlin metadata for StopWatch inline functions |
|
0 commit comments