Debug与发布不一致的问题记录

作者: waiwaaa | 来源:发表于2019-07-14 18:07 被阅读5次

    在Android studio里直接debug调试正常,但发布出来安装就不正常。在安装后连接adb可以看到如下错误日志

    2019-07-06 13:27:19.464 28375-28375/xxx W/System.err: java.lang.NoSuchMethodException: <init> [class android.view.View]
    2019-07-06 13:27:19.464 28375-28375/xxx W/System.err:     at java.lang.Class.getConstructor0(Class.java:2320)
    2019-07-06 13:27:19.464 28375-28375/xxx W/System.err:     at java.lang.Class.getConstructor(Class.java:1725)
    2019-07-06 13:27:19.464 28375-28375/xxx W/System.err:     at MessageItemHolderFactory.createMessageHolder(MessageItemHolderFactory.java:134)
    2019-07-06 13:27:19.464 28375-28375/xxx W/System.err:     at WechatConvListAdapter.onCreateViewHolder(WechatConvListAdapter.java:46)
    2019-07-06 13:27:19.464 28375-28375/xxx W/System.err:     at WechatConvListAdapter.onCreateViewHolder(WechatConvListAdapter.java:21)
    2019-07-06 13:27:19.464 28375-28375/xxx W/System.err:     at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6903)
    2019-07-06 13:27:19.465 28375-28375/cn.ac.multiwechat W/System.err:     at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6075)
    

    报错点为如下

    try {
                    Constructor<? extends BaseMessageItemHolder> constructor = holderClass.getConstructor(View.class);
                    holder = constructor.newInstance(view);
                } catch (NoSuchMethodException e) {
                    e.printStackTrace();
                    holder = null;
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                    holder = null;
                } catch (InstantiationException e) {
                    e.printStackTrace();
                    holder = null;
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                    holder = null;
                }
    

    原因:对应的构造方法没有设置public,导致反射构造器报错。但为啥子Debug时会正常呢?

    相关文章

      网友评论

        本文标题:Debug与发布不一致的问题记录

        本文链接:https://www.haomeiwen.com/subject/dgephctx.html