0
我使用下面的方法来强制在我的Android ActionBar上堆叠的选项卡。Android Proguard - Reflection java.lang.reflect调用不工作
当我开始使用proguard时,Class操作不再起作用。没有收到错误消息,我只是没有得到堆栈选项卡ActionBar。
这就是我的proguard规则。有什么清楚的我失踪了吗?
-keepattributes Signature
-keepattributes *Annotation*
-keep class java.lang.reflect.** { *; }
-keep class com.company.myapplication1.SetStackedTabs.** { *; }
_
public static void SetStackedTabs(Object inActionBar, final boolean inHasEmbeddedTabs){
// get the ActionBar class
Class<?> actionBarClass = inActionBar.getClass();
// if it is a Jelly Bean implementation (ActionBarImplJB), get the super class (ActionBarImplICS)
if ("android.support.v7.app.ActionBarImplJB".equals(actionBarClass.getName()))
{
actionBarClass = actionBarClass.getSuperclass();
}
// if Android 4.3 >
if ("android.support.v7.app.ActionBarImplJBMR2".equals(actionBarClass.getName())){
actionBarClass = actionBarClass.getSuperclass().getSuperclass();
}
try
{
// try to get the mActionBar field, because the current ActionBar is probably just a wrapper Class
// if this fails, no worries, this will be an instance of the native ActionBar class or from the ActionBarImplBase class
final Field actionBarField = actionBarClass.getDeclaredField("mActionBar");
actionBarField.setAccessible(true);
inActionBar = actionBarField.get(inActionBar);
actionBarClass = inActionBar.getClass();
}
catch (IllegalAccessException e) {}
catch (IllegalArgumentException e) {}
catch (NoSuchFieldException e) {}
try
{
// now call the method setHasEmbeddedTabs, this will put the tabs inside the ActionBar
// if this fails, you're on you own <img class="wp-smiley" alt=";-)" src="http://www.blogc.at/wp-includes/images/smilies/icon_wink.gif">
final Method method = actionBarClass.getDeclaredMethod("setHasEmbeddedTabs", new Class[] { Boolean.TYPE });
method.setAccessible(true);
method.invoke(inActionBar, new Object[]{ inHasEmbeddedTabs });
}
catch (NoSuchMethodException e) {}
catch (InvocationTargetException e) {}
catch (IllegalAccessException e) {}
catch (IllegalArgumentException e) {}
}
Proguard混淆了您的代码。取决于proguard配置类,方法,字段,局部变量被重命名。因此,在这里你检查一个类名是否与另一个类相同,但是proguard将它改为类A.class。使用-keep类的proguard不会改变匹配给定模式的类。 – JEY
您在哪个位置添加了-keep类android.support.v7。** {*; }?我面临同样的问题。 – Anirudh