有一个非常好用的库可以在Android中创建树形视图,AndroidTreeView。
这个库在我开启proguard
后出现了崩溃问题。
注意:我有一个包含5个片段的ViewPager
,每个片段都使用了treeview
。
使用默认的progaurd设置时,我会收到以下错误:
java.lang.RuntimeException: Could not instantiate class class com.mehdok.c.c
at com.mehdok.e.a.a.b(Unknown Source)
at com.mehdok.e.a.a.a(Unknown Source)
at com.mehdok.e.a.a.b(Unknown Source)
at com.mehdok.e.a.a.b(Unknown Source)
at com.mehdok.e.a.a.a(Unknown Source)
at com.mehdok.b.b.b(Unknown Source)
at com.mehdok.b.b.onCreateView(Unknown Source)
我尝试修改ProGuard设置:
-keep public class com.mehdok.views.treeview.AndroidTreeView
-keep public class com.mehdok.views.treeview.SimpleViewHolder
-keep public class com.mehdok.views.treeview.TreeNode
-keep public interface com.mehdok.views.treeview.TreeNode$TreeNodeClickListener
-keep public class com.mehdok.views.treeview.TreeNode$BaseNodeViewHolder
-keep public class com.mehdok.views.treeview.TreeNodeWrapperView
-keep class com.mehdok.views.treeview.** { *; }
-keep public class com.mehdok.holders.TreeViewHolder
-keep public class com.mehdok.holders.TreeViewHolder$TreeViewItem
现在我遇到了这个错误:
java.lang.RuntimeException: Could not instantiate class class com.mehdok.holders.TreeViewHolder
at com.mehdok.views.treeview.AndroidTreeView.getViewHolderForNode(Unknown Source)
at com.mehdok.views.treeview.AndroidTreeView.addNode(Unknown Source)
at com.mehdok.views.treeview.AndroidTreeView.expandNode(Unknown Source)
at com.mehdok.views.treeview.AndroidTreeView.getView(Unknown Source)
at com.mehdok.views.treeview.AndroidTreeView.getView(Unknown Source)
at com.mehdok.b.b.b(Unknown Source)
at com.mehdok.b.b.onCreateView(Unknown Source)
Proguard相关的一部分是mapping
文本:
com.mehdok.fragments.Tab1Fragment -> com.mehdok.b.b:
com.mehdok.fragments.Tab1Fragment mInstance -> a
android.widget.FrameLayout baseView -> b
com.mehdok.fragments.Tab1Fragment getInstance() -> a
android.view.View onCreateView(android.view.LayoutInflater,android.view.ViewGroup,android.os.Bundle) -> onCreateView
void findViews(android.view.View) -> a
void fillView() -> b
TreeViewHolder.java
public class TreeViewHolder extends TreeNode.BaseNodeViewHolder<TreeViewHolder.TreeViewItem>
{
public TreeViewHolder(Context context)
{
super(context);
}
@Override
public View createNodeView(TreeNode node, TreeViewItem value)
{
final LayoutInflater inflater = LayoutInflater.from(context);
final View view = inflater.inflate(R.layout.treeview_layout, null, false);
TextView tvValue = (TextView) view.findViewById(R.id.row_text);
tvValue.setText(value.nodeName);
return view;
}
@Override
public void toggle(boolean active)
{
super.toggle(active);
}
public static class TreeViewItem
{
public String nodeName;
public int nodeNavNum;
public int nodeDeep;
public TreeViewItem(String name, int nav, int deep)
{
nodeName = name;
nodeNavNum = nav;
nodeDeep = deep;
}
}
}
Tab1Fragment.java
public class Tab1Fragment extends Fragment
{
private static Tab1Fragment mInstance;
private FrameLayout baseView;
public static Tab1Fragment getInstance()
{
if(mInstance == null)
{
mInstance = new Tab1Fragment();
}
return mInstance;
}
public Tab1Fragment()
{
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_tab1, container, false);
findViews(v);
fillView();
return v;
}
private void findViews(View v)
{
baseView = (FrameLayout)v.findViewById(R.id.tab1_base_layout);
}
private void fillView()
{
TreeNode root = TreeCreator.createTitle1Tree();
AndroidTreeView tView = new AndroidTreeView(getActivity(), root);
tView.setDefaultAnimation(true);
tView.setDefaultContainerStyle(R.style.TreeNodeStyle);
tView.setDefaultViewHolder(TreeViewHolder.class);
//tView.setDefaultNodeClickListener(nodeClickListener);
baseView.addView(tView.getView());
}
}
我应该如何配置Proguard才能发挥作用呢?非常感谢您的帮助。