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