嘿,我正在使用 dexguard 混淆我的应用程序,到目前为止一切正常。现在我正在尝试将图标添加到操作栏菜单。没有 dexguard 混淆,图标会显示,但随着它消失(文本仍然存在)。我觉得这与 xml<menu>
标签有关,因为混淆不会影响其他衬里/相对布局。
这是我的 actions.xml(在 res.layout 下,图标在 res.drawble-xxx 下):
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent">
<item android:id="@+id/action_1"
android:title="action_1"
android:icon="@drawable/action_1_icon"
/>
<item android:id="@+id/action_2"
android:title="action_2"
android:icon="@drawable/action_2_icon"
/>
<item android:id="@+id/action_3"
android:title="action_3"
android:icon="@drawable/action_3_icon"
/>
</menu>
我也尝试以编程方式添加它们
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem action_1 = menu.findItem(R.id.action_1);
action_1.setIcon(getResources().getDrawable(R.drawable.action_1_icon));
MenuItem action_2 = menu.findItem(R.id.action_2);
action_2.setIcon(getResources().getDrawable(R.drawable.action_2_icon));
MenuItem action_3 = menu.findItem(R.id.action_3);
action_3.setIcon(getResources().getDrawable(R.drawable.action_3_icon));
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.layout.actions, menu);
return super.onCreateOptionsMenu(menu);
}
但仍然混淆删除菜单图标。
编辑:dexguard 配置
-verbose
-dalvik
-dontshrink
-dontoptimize
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-keepresourcexmlattributenames
manifest/installLocation,
manifest/versionCode,
manifest/application/*/intent-filter/*/name
-dontwarn javax.management.**
-dontwarn java.lang.management.**
-dontwarn org.apache.log4j.**
-dontwarn org.apache.commons.logging.**
-dontwarn org.slf4j.**
-dontwarn org.json.**
-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.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keep class javax.** { *; }
-keep class org.** { *; }
-keep class twitter4j.** { *; }
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-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 ** CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
-keep public interface com.android.vending.licensing.ILicensingService
-dontwarn android.support.**