Android混淆崩溃问题

Android混淆崩溃问题

    • 一、原始崩溃日志
    • 二、还原后的崩溃日志
    • 三、源代码
    • 四、解决方案
    • 五、参考文章
    • 六、Finally

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

一、原始崩溃日志

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)

二、还原后的崩溃日志

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异常。

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());
        }
    }
}

四、解决方案

不要混淆数据类。

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

-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

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

你可能感兴趣的:(Android混淆崩溃问题)