在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来为我工作呢?
任何帮助都将不胜感激。
最佳答案
保持视图保持架解决了问题
-keep public class com.mehdok.holders.TreeViewHolder
-keep public class com.mehdok.holders.TreeViewHolder$TreeViewItem
-keepclassmembers class com.mehdok.holders.TreeViewHolder {
public *;
private *;
}