Repository navigation
Commit ebff162
ADFA-6016: Fix Layout Editor crash on release IDE builds (#98)
* Fix Layout Editor crash on release IDE builds
LayoutEditorFragment crashed at onCreate with
ClassCastException: LayoutEditorFragment cannot be cast to
androidx.activity.result.ActivityResultCaller.
The release IDE APK is R8-shrunk and nothing in it uses
ActivityResultCaller as a type, so R8 drops the interface and strips it
from Fragment's implements list. The plugin bundles androidx.activity,
and the plugin DexClassLoader is parent-first: Fragment resolves to the
host's class while ActivityResultCaller falls through to the plugin's
own bundled copy. The two are unrelated types, so passing the fragment
into FileCreator/FilePicker (both declared ActivityResultCaller) failed
the cast. Unminified debug IDE builds keep the interface, which is why
this only showed up on release.
Take Fragment instead and call registerForActivityResult on it, matching
APK-Analyzer, Markdown-Previewer and Sketch-to-UI. ActivityResultContract,
ActivityResultCallback and ActivityResultLauncher all survive in the
release host, so the launchers still cross the boundary correctly. The
unused AppCompatActivity constructor of FilePicker goes with it.
Verified on an emulator running the release IDE (C-r-0911-2020): plugin
installs, Layout Editor renders activity_main.xml, and Resources Manager
(three FilePicker instances) opens without a crash.
* Stop Layout Editor calling Apache Commons methods the host shrank away
Same root cause as the ActivityResultCaller fix: the plugin DexClassLoader
is parent-first, so any class the R8-shrunk release IDE also ships resolves
to the host's copy. commons-text and commons-io are both in the host, but
only the slice the IDE itself uses survived R8:
StringEscapeUtils keeps the ESCAPE_* fields and unescapeJava; every
escapeXxx(String) method is gone, escapeXml11 included
FileUtils keeps listFiles(File, IOFileFilter, IOFileFilter) and
listFiles(File, FileFilter); the (File, String[], boolean)
overload the plugin calls is gone
escapeXml11 is the NoSuchMethodError reported from XmlLayoutGenerator; the
listFiles one had not been hit yet but crashes Resources Manager the moment a
project has a drawable folder.
Neither needs a library. TextUtils.htmlEncode escapes the same characters an
XML attribute or element body needs and is a framework API, so no amount of
host shrinking can remove it. File.listFiles with a filter is what the same
file already does a few lines down in buildDpiVersionMap. With those two gone
nothing else in the plugin uses Apache Commons, so both dependencies go too
(9.2 MB -> 8.7 MB).
StringResourceAdapter used lang3's deprecated StringEscapeUtils, which happens
to work today only because the host dropped that class entirely and the
plugin's bundled copy loads instead. Same treatment, so it cannot regress when
the host's keep rules change.
Verified on an emulator running the release IDE (C-r-0911-2020): the layout
renders, navigating back to the editor no longer crashes, Export Layout runs
the generator end to end, and Resources Manager lists a drawable folder
(png/jpg/gif/xml, correctly skipping webp).
* ADFA-6016 | Fix the Compose Preview compiler toolchain against Kotlin 2.3.21
Two defects sat in front of the preview, each hidden by the one before it.
Both show up only on a release IDE, because that is where the plugin gets far
enough to start the compiler at all.
The Kotlin compiler runs as a JVM subprocess, and its bootstrap classpath
listed six artifacts with no kotlinx-coroutines. kotlin-compiler-embeddable
2.3.21 touches CoroutineScope while building its CoreApplicationEnvironment, so
the subprocess died with NoClassDefFoundError before compiling anything. The
jar is already in the IDE's bundled local Maven repo; it was simply never
referenced.
Past that, the compiler rejected the bundled Compose compiler plugin: the
compose-jars.zip asset carries 1.5.10, which demands Kotlin 1.9.22. Since
Kotlin 2.0 the Compose compiler ships with Kotlin, and the same bundled repo
holds kotlin-compose-compiler-plugin-embeddable 2.3.21, so resolve it there
and stay version-matched to whichever compiler the IDE ships rather than to a
zip frozen in June. getRuntimeJars keeps excluding the bundled jar by path so
the stale copy cannot leak onto the runtime classpath.
Verified on an emulator running a release IDE built from this branch's proguard
change: Compose Preview renders a @Preview composable on-device.
---------
Co-authored-by: Daniel Alome <astrocoder007@gmail.com>1 parent a1e6f36 commit ebff162
7 files changed
Lines changed: 27 additions & 50 deletions
File tree
- plugins
- Jetpack-Compose-Preview/src/main/kotlin/org/appdevforall/composepreview/compiler
- Layout-Editor
- src/main/java/org/appdevforall/codeonthego/layouteditor
- adapters
- fragments/resources
- tools
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| |||
160 | 162 | | |
161 | 163 | | |
162 | 164 | | |
163 | | - | |
| 165 | + | |
| 166 | + | |
164 | 167 | | |
165 | 168 | | |
166 | 169 | | |
| |||
174 | 177 | | |
175 | 178 | | |
176 | 179 | | |
| 180 | + | |
177 | 181 | | |
178 | 182 | | |
179 | 183 | | |
180 | 184 | | |
181 | 185 | | |
182 | 186 | | |
183 | 187 | | |
184 | | - | |
| 188 | + | |
185 | 189 | | |
186 | | - | |
| 190 | + | |
187 | 191 | | |
188 | 192 | | |
189 | 193 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | | - | |
94 | 92 | | |
95 | 93 | | |
96 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | | - | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
| |||
58 | 57 | | |
59 | 58 | | |
60 | 59 | | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
146 | 144 | | |
147 | 145 | | |
148 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | | - | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
| 134 | + | |
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
| 155 | + | |
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
| 176 | + | |
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | 18 | | |
24 | | - | |
25 | | - | |
26 | 19 | | |
27 | | - | |
| 20 | + | |
28 | 21 | | |
29 | 22 | | |
30 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | 4 | | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
10 | | - | |
11 | 8 | | |
12 | 9 | | |
13 | | - | |
14 | 10 | | |
15 | 11 | | |
16 | 12 | | |
17 | 13 | | |
18 | 14 | | |
19 | 15 | | |
20 | | - | |
21 | | - | |
| 16 | + | |
22 | 17 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 18 | + | |
35 | 19 | | |
36 | 20 | | |
37 | | - | |
| 21 | + | |
38 | 22 | | |
39 | 23 | | |
40 | | - | |
| 24 | + | |
41 | 25 | | |
42 | | - | |
| 26 | + | |
43 | 27 | | |
44 | 28 | | |
45 | 29 | | |
| |||
70 | 54 | | |
71 | 55 | | |
72 | 56 | | |
73 | | - | |
| 57 | + | |
74 | 58 | | |
75 | 59 | | |
76 | 60 | | |
| |||
0 commit comments