Android混淆崩溃问题

Android混淆崩溃问题

上周四,导出『神马笔记』发布包的时候,遇到混淆后NullPointerException问题。

一、原始崩溃日志

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
java.lang.NullPointerException: throw with null exception
at app.haiyunshan.whatsnote.tag.c.a.b(Unknown Source:1)
at app.haiyunshan.whatsnote.tag.b.b.<init>(Unknown Source:24)
at app.haiyunshan.whatsnote.tag.b.b.<init>(Unknown Source:1)
at app.haiyunshan.whatsnote.tag.b.b$a.a(Unknown Source:2)
at app.haiyunshan.whatsnote.tag.b.a.apply(Unknown Source:4)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:194)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1390)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:235)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:501)
at app.haiyunshan.whatsnote.tag.b.b$a.a(Unknown Source:44)
at app.haiyunshan.whatsnote.tag.b.b.m(Unknown Source:8)
at app.haiyunshan.whatsnote.record.b.Ua.f(Unknown Source:0)
at app.haiyunshan.whatsnote.record.b.wa.apply(Unknown Source:2)
at java.util.Optional.map(Optional.java:211)
at app.haiyunshan.whatsnote.record.b.Ua.j(Unknown Source:19)
at app.haiyunshan.whatsnote.record.b.Ua.<init>(Unknown Source:9)
at app.haiyunshan.whatsnote.record.b.Ua.a(Unknown Source:2)
at app.haiyunshan.whatsnote.record.b.ra.apply(Unknown Source:2)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:194)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1390)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:235)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:501)
at app.haiyunshan.whatsnote.record.b.Ua.<init>(Unknown Source:49)
at app.haiyunshan.whatsnote.record.b.Ua.h(Unknown Source:4)
at app.haiyunshan.whatsnote.record.EntranceFragment$TagSection.<init>(Unknown Source:7)
at app.haiyunshan.whatsnote.record.EntranceFragment.b(Unknown Source:225)
at androidx.fragment.app.h.g(Unknown Source:13)
at androidx.fragment.app.t.a(Unknown Source:639)
at androidx.fragment.app.t.h(Unknown Source:38)
at androidx.fragment.app.t.a(Unknown Source:46)
at androidx.fragment.app.a.e(Unknown Source:165)
at androidx.fragment.app.t.a(Unknown Source:38)
at androidx.fragment.app.t.b(Unknown Source:114)
at androidx.fragment.app.t.c(Unknown Source:88)
at androidx.fragment.app.t.p(Unknown Source:21)
at androidx.fragment.app.t.e(Unknown Source:9)
at androidx.fragment.app.t.f(Unknown Source:6)
at androidx.fragment.app.k.a(Unknown Source:4)
at androidx.fragment.app.FragmentActivity.onStart(Unknown Source:15)
at androidx.appcompat.app.AppCompatActivity.onStart(Unknown Source:0)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1392)
at android.app.Activity.performStart(Activity.java:7252)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2970)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6806)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

二、还原后的崩溃日志

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
java.lang.NullPointerException: throw with null exception
at app.haiyunshan.whatsnote.tag.entry.ColorEntry.getIcon(Unknown Source:1)
at app.haiyunshan.whatsnote.tag.entity.ColorEntity.<init>(Unknown Source:24)
at app.haiyunshan.whatsnote.tag.entity.ColorEntity.<init>(Unknown Source:1)
at app.haiyunshan.whatsnote.tag.entity.ColorEntity$Factory.create(Unknown Source:2)
lambda$create$62
at app.haiyunshan.whatsnote.tag.entity.-$$Lambda$ColorEntity$Factory$6WW9IJhdkHoDaTXQiSt52V3OmcM.apply(Unknown Source:4)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:194)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1390)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:235)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:501)
at app.haiyunshan.whatsnote.tag.entity.ColorEntity$Factory.create(Unknown Source:44)
lambda$create$62
at app.haiyunshan.whatsnote.tag.entity.ColorEntity.obtain(Unknown Source:8)
at app.haiyunshan.whatsnote.record.entity.TagEntity.lambda$getColor$86(Unknown Source:0)
at app.haiyunshan.whatsnote.record.entity.-$$Lambda$TagEntity$j9logEgPJpykZJA9QwTxs0W8WDI.apply(Unknown Source:2)
at java.util.Optional.map(Optional.java:211)
at app.haiyunshan.whatsnote.record.entity.TagEntity.getColor(Unknown Source:19)
at app.haiyunshan.whatsnote.record.entity.TagEntity.<init>(Unknown Source:9)
at app.haiyunshan.whatsnote.record.entity.TagEntity.add(Unknown Source:2)
areContentsTheSame
countOfRecord
lambda$countOfRecord$88
lambda$countOfRecord$89
lambda$countOfRecord$90
lambda$getColor$85
lambda$new$84
setColor
at app.haiyunshan.whatsnote.record.entity.-$$Lambda$TagEntity$EkanLFnR-JUISmAi7b6E8piShD8.apply(Unknown Source:2)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:194)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1390)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:235)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:501)
at app.haiyunshan.whatsnote.record.entity.TagEntity.<init>(Unknown Source:49)
at app.haiyunshan.whatsnote.record.entity.TagEntity.toList(Unknown Source:4)
at app.haiyunshan.whatsnote.record.EntranceFragment$TagSection.<init>(Unknown Source:7)
at app.haiyunshan.whatsnote.record.EntranceFragment.lambda$onRestart$64(Unknown Source:225)
onActivityCreated
onDoneClick
requestDrag
at androidx.fragment.app.Fragment.getAllowReturnTransitionOverlap(Unknown Source:13)
performActivityCreated
setRetainInstance
at androidx.fragment.app.FragmentManagerImpl.addAddedFragments(Unknown Source:639)
addBackStackState
addFragment
animateRemoveFragment
attachController
attachFragment
beginTransaction
completeExecute
dispatchConfigurationChanged
dispatchContextItemSelected
dispatchCreateOptionsMenu
dispatchMultiWindowModeChanged
dispatchOnFragmentActivityCreated
dispatchOnFragmentAttached
dispatchOnFragmentViewCreated
dispatchOptionsMenuClosed
dump
enqueueAction
executeOps
executePostponedTransaction
findFragmentById
findFragmentByTag
getAnimationListener
getFragment
loadAnimation
makeFadeAnimation
makeOpenCloseAnimation
modifiesAlpha
modifiesAlpha
moveToState
moveToState
popBackStack
popBackStackImmediate
popBackStackState
postponePostponableTransactions
putFragment
restoreAllState
setBackStackIndex
setRetaining
shouldRunOnHWLayer
throwException
at androidx.fragment.app.FragmentManagerImpl.dispatchDestroy(Unknown Source:38)
dispatchOnFragmentViewDestroyed
moveFragmentToExpectedState
at androidx.fragment.app.FragmentManagerImpl.addAddedFragments(Unknown Source:46)
addBackStackState
addFragment
animateRemoveFragment
attachController
attachFragment
beginTransaction
completeExecute
dispatchConfigurationChanged
dispatchContextItemSelected
dispatchCreateOptionsMenu
dispatchMultiWindowModeChanged
dispatchOnFragmentActivityCreated
dispatchOnFragmentAttached
dispatchOnFragmentViewCreated
dispatchOptionsMenuClosed
dump
enqueueAction
executeOps
executePostponedTransaction
findFragmentById
findFragmentByTag
getAnimationListener
getFragment
loadAnimation
makeFadeAnimation
makeOpenCloseAnimation
modifiesAlpha
modifiesAlpha
moveToState
moveToState
popBackStack
popBackStackImmediate
popBackStackState
postponePostponableTransactions
putFragment
restoreAllState
setBackStackIndex
setRetaining
shouldRunOnHWLayer
throwException
at androidx.fragment.app.BackStackRecord.executeOps(Unknown Source:165)
at androidx.fragment.app.FragmentManagerImpl.addAddedFragments(Unknown Source:38)
addBackStackState
addFragment
animateRemoveFragment
attachController
attachFragment
beginTransaction
completeExecute
dispatchConfigurationChanged
dispatchContextItemSelected
dispatchCreateOptionsMenu
dispatchMultiWindowModeChanged
dispatchOnFragmentActivityCreated
dispatchOnFragmentAttached
dispatchOnFragmentViewCreated
dispatchOptionsMenuClosed
dump
enqueueAction
executeOps
executePostponedTransaction
findFragmentById
findFragmentByTag
getAnimationListener
getFragment
loadAnimation
makeFadeAnimation
makeOpenCloseAnimation
modifiesAlpha
modifiesAlpha
moveToState
moveToState
popBackStack
popBackStackImmediate
popBackStackState
postponePostponableTransactions
putFragment
restoreAllState
setBackStackIndex
setRetaining
shouldRunOnHWLayer
throwException
at androidx.fragment.app.FragmentManagerImpl.allocBackStackIndex(Unknown Source:114)
completeShowHideFragment
dispatchOnFragmentCreated
dispatchOnFragmentDestroyed
dispatchOnFragmentPreAttached
dispatchOptionsItemSelected
dispatchPictureInPictureModeChanged
dispatchPrepareOptionsMenu
execSingleAction
executeOpsTogether
findFragmentByWho
freeBackStackIndex
generateOpsForPendingActions
getFragments
makeRemovedFragmentsInvisible
setHWLayerAnimListenerIfAlpha
transitToStyleIndex
at androidx.fragment.app.FragmentManagerImpl.detachFragment(Unknown Source:88)
dispatchOnFragmentDetached
dispatchOnFragmentPreCreated
ensureExecReady
isStateAtLeast
isStateSaved
removeRedundantOperationsAndExecute
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(Unknown Source:21)
findFragmentUnder
at androidx.fragment.app.FragmentManagerImpl.dispatchOnFragmentResumed(Unknown Source:9)
dispatchStateChange
hideFragment
popBackStackImmediate
at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(Unknown Source:6)
dispatchOnFragmentStarted
makeActive
at androidx.fragment.app.FragmentController.attachHost(Unknown Source:4)
createController
dispatchActivityCreated
dispatchConfigurationChanged
dispatchContextItemSelected
dispatchCreateOptionsMenu
dispatchMultiWindowModeChanged
dispatchOptionsMenuClosed
findFragmentByWho
onCreateView
restoreAllState
at androidx.fragment.app.FragmentActivity.onStart(Unknown Source:15)
at androidx.appcompat.app.AppCompatActivity.onStart(Unknown Source:0)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1392)
at android.app.Activity.performStart(Activity.java:7252)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2970)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6806)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

三、源代码

在调用ColorEntry#getIcon()时首先判断调用对象不为null。但依然发生NullPointerException异常。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public class ColorEntity extends BaseEntitySet<ColorEntity, ColorEntry> {

public static final ColorEntity TRANSPARENT = new ColorEntity(null, null);

private static ColorEntity instance;

int icon = Color.TRANSPARENT;
int color = 0xff474747;
int check = 0xff606060;
int background = 0xffe0e0e0;

ColorEntity(@NonNull Context context, @Nullable ColorEntry entry) {
this(context, entry, null);
}

ColorEntity(@NonNull Context context, @Nullable ColorEntry entry, @Nullable List<ColorEntity> list) {
super(context, entry, list);

if (entry != null) {
this.icon = ColorUtils.parse(entry.getIcon());
this.color = ColorUtils.parse(entry.getColor());
this.check = ColorUtils.parse(entry.getCheck());
this.background = ColorUtils.parse(entry.getBackground());
}
}
}

四、解决方案

不要混淆数据类。

经过几天测试,发现此方法可行。

1
-keep public class * extends club.andnext.base.BaseEntry

五、参考文章

  1. Android studio 混淆打包安装后报错NullPointerException int java.util.List.size()
  2. Android studio 混淆打包安装后报错NullPointerException int java.util.List.size()

六、Finally

~一重山~两重山~山远天高烟水寒~相思枫叶丹~