在android AndroidTreeView中创建树视图真的很棒。
这个库工作正常,直到我启用proguard
,然后应用程序崩溃。
注意:我有ViewPager
个5个片段,所有片段都使用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());
}
}
那么我如何配置progaurd为我工作?
任何帮助都将不胜感激。
答案 0 :(得分:2)
让视图持有者解决问题
-keep public class com.mehdok.holders.TreeViewHolder
-keep public class com.mehdok.holders.TreeViewHolder$TreeViewItem
-keepclassmembers class com.mehdok.holders.TreeViewHolder {
public *;
private *;
}