我已经使用 ActionBar 在 Android 4.1 版本中开发了该应用程序。如果我不混淆 ActionBar 代码意味着菜单项显示在 ActionBar 中,而混淆 ActionBar 代码后,ActionBar 中的菜单项根本不显示。混淆代码如下所示。
-injars input.jar
-outjars output.obfuscated.jar
-libraryjars android.jar
-libraryjars android-support-v4.jar
-libraryjars annotations.jar
-dontpreverify
-dontskipnonpubliclibraryclassmembers
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-keepparameternames
-renamesourcefileattribute SourceFile
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-keep public class * {
public protected *;
}
-keepclassmembernames class * {
java.lang.Class class$(java.lang.String);
java.lang.Class class$(java.lang.String, boolean);
}
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.content.Context {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
是否有任何程序来混淆 ActionBar 代码?
编辑1:
public static void AddMenuItem(String path, int id, String itemLabel)
{
try
{
if(menu!=null)
{
menu.add(0, id, 0, itemLabel).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
MenuItem item=menu.findItem(id);
InputStream ims = sActiveContext.getAssets().open(path);
Drawable d = Drawable.createFromStream(ims, null);
item.setIcon(d);
}
}
catch(Exception error)
{
}
}
我没有使用菜单 xml 资源。我只通过java代码完成了添加,删除操作栏中的菜单项。