7

Google は、開発者がバイト コードを難読化することを推奨しています。

http://android-developers.blogspot.com/2010/09/proguard-android-and-licensing-server.html

私は Google の指示に従って難読化された Android アプリを入手しましたが、一見するとうまくいくように見えました。しかし、難読化されていないアプリにはない奇妙なバグがいくつか導入されました。この構成に到達するために、ProGuard オプションをオフにし続けました。

-dontoptimize -dontshrink -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontpreverify -verbose

それでもバグはあります。純粋な難読化だけを得るためにオフにできるものは他にありますか? 難読化は良いことですが、ProGuard の他の機能をオフにするつもりです。

4

1 に答える 1

8

これは私が使用するものです:

-libraryjars ${android.jar}
-injars      temp.jar
-outjars    proguard.jar

#-printseeds: Prints the un-obfuscated filenames
-printseeds
-printmapping mapping-used-to-retrace-exceptions.txt
-verbose

#-dontusemixedcaseclassnames: Necessary when building on windows where x.class and X.class is the same file
-dontusemixedcaseclassnames

#-repackageclasses: Adds further obfuscation, Counter-indication: classes that look for resource files in their package directories will no longer work properly if they are moved elsewhere. When in doubt, just leave the packaging untouched by not using this option.
-repackageclasses ''

#-dontskipnonpubliclibraryclasses: Counter-indication: you probably shouldn't use this option when processing code that is to be used as a library, since classes and class members that weren't designed to be public in the API may become public.
-dontskipnonpubliclibraryclasses

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep 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*(...); 
}
-keep class * extends android.preference.Preference { 
  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*(...); 
}    
# LVL License binder class
-keep class com.android.vending.licensing.ILicensingService    
# This is necessary for LVL among others. According to proguard doc java accesses enum fields by introspection.
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
#Optimization settings
-dontoptimize

難読化しますが、Android で必要なクラスのパブリック メソッドとクラス名を公開します。あなたが要求したように、最適化されません-メソッドとコンストラクターが削除されたため、最適化によりプログラムが壊れる可能性が高くなります。

最適化を含めて試してみたい場合は、次のようにします (上記の -dontoptimize オプションを削除することを忘れないでください)。

#Optimization settings    
# Keep (ie. don't remove) all public constructors of all public classes, but still obfuscate+optimize their content. This is necessary because optimization removes constructors which I use through reflection.
-keepclassmembers class * {
    <init>(...);
}

-optimizationpasses 7
-allowaccessmodification
# The -optimizations option disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle. 
-optimizations !code/simplification/arithmetic 

私は proguard 4.5 を使用していますが、他のバージョンもおそらく同様に機能します。

于 2010-11-03T11:02:52.103 に答える