2013-07-16 21 views
5

如果我有一個Class B實現Interface A和Proguard不知道該接口的存在,我如何保留實現接口A的抽象方法的方法的名稱?如何保持類方法名稱覆蓋實現另一種方法被混淆?

請注意,我想保留方法名稱,但我確實希望他們的內容被模糊處理。

更新: 這是我有什麼(請注意評論):

public class MyService extends Service { 

    // an anonymous class that implements ServiceConnection 
    private ServiceConnection myConnection = new ServiceConnection() 
    { 
     // don't change the following method's name 
     @Override 
     public void onServiceConnected(ComponentName className, IBinder service) 
     { 
      // I want this section to be obfuscated 
     } 

} 

我想對於這些種情況下的通用解決方案 - 在狀態界面名字,我不想ProGuard配置。

+0

@Raghunandan您發佈的評論是irrelavant!你在這裏回答別人的問題!請在http://techspreadwithshraddha.wordpress.com/2013/03/26/android-progaurd/ – Shraddha

+0

@Shraddha感謝提醒,找到我的Progaurd博客。可能打開了我的瀏覽器的錯誤標籤。 – Raghunandan

回答

6
  • 保持所有公共類的名字和他們的 公共保持(防止混淆)和受保護的方法。
  • 在非公開課和保持(防止混淆)所有公共和 受保護的方法。這將使可能實現或擴展其他方法的方法不被混淆。
  • 不要保留本地變量屬性(使 確保「LocalVariableTable」和「LocalVariableTypeTable」不是 在「-keepattributes」選項中聲明)。

所以,你的.pro文件應該是這樣的 -

#Keeping all public class names and keep (prevent obfuscation) of their public and protected methods 
-keep public class * { 
    public protected <methods>; 
} 

# Keep (prevent obfuscation) all public and protected methods in non-public classes. 
# Notice that the non-public class names will still get obfuscated 
-keepclassmembers !public class * { 
    public protected <methods>; 
} 

# Don't keep the local variables attributes (LocalVariableTable and LocalVariableTypeTable are dropped). 
-keepattributes Exceptions,Signature,Deprecated,SourceFile,SourceDir,LineNumberTable,Synthetic,EnclosingMethod,RuntimeVisibleAnnotations,RuntimeInvisibleAnnotations,RuntimeVisibleParameterAnnotations,RuntimeInvisibleParameterAnnotations,AnnotationDefault,InnerClasses,*Annotation* 
+0

+1這樣可以解決問題 – Shraddha

+0

@RonTesler,如何只混淆一個類及其公共方法? –

0

我寫了一個Progaurding Android應用程序的博客。請檢查下面

http://techspreadwithshraddha.wordpress.com/2013/03/26/android-progaurd/

ProGuard的鏈接可以做你的描述。如果你不希望它重命名的類和方法,請嘗試以下之一:

-keep,allowshrinking,allowoptimization class * { <methods>; } 

希望這有助於

+0

對不起,如果我不清楚它 - 我不想指定接口名稱。我試圖找到一個通用的解決方案。可能嗎? –

+0

我編輯了我的答案。注意答案中的'*',只要你想保持通用就寫'*'。請按照它會幫助你的博客。它有一個Android應用程序的例子 – Shraddha

+0

糾正我,如果我錯了,但按照你的建議,保持類名和所有的方法名稱,但他們也不會被混淆。 –