简体   繁体   English

如何在Eclipse中模糊我的代码? (机器人)

[英]How can I obfuscate my code in Eclipse? (Android)

I am new in android application. 我是Android应用程序的新手。 I write an application and need to obfuscate it in eclipse. 我编写了一个应用程序,需要在eclipse中对其进行模糊处理。 I tried to use following tutorial: 我尝试使用以下教程:

http://developer.android.com/tools/help/proguard.html http://developer.android.com/tools/help/proguard.html

but when i created my project the eclipse did not produce any "proguard.cfg" file. 但是当我创建我的项目时,eclipse没有产生任何“proguard.cfg”文件。 I just have a "project.properties" that uncomment the following line of that. 我只有一个“project.properties”取消注释以下行。

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt proguard.config = $ {} sdk.dir /tools/proguard/proguard-android.txt:proguard-project.txt

I put instead of {sdk.dir} path to sdk. 我把{sdk.dir}路径改为sdk。 I don't have progurd-android.txt as well. 我也没有progurd-android.txt。 is there any clear step by step for beginner how to obfuscate code in android? 对于初学者如何在android中混淆代码是否有任何明确的步骤? or is it possible to you to explain it for me? 或者你有可能为我解释一下吗? Thanks for help. 感谢帮助。

First, you should comment out this line on project.ptoperties: 首先,你应该在project.ptoperties上注释掉这一行:

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt proguard.config = $ {} sdk.dir /tools/proguard/proguard-android.txt:proguard-project.txt

Then you should write your rules to proguard-project.txt This is an example from http://proguard.sourceforge.net/#manual/examples.html : 然后你应该把你的规则编写到proguard-project.txt这是http://proguard.sourceforge.net/#manual/examples.html的一个例子:

-injars      bin/classes
-injars      libs
-outjars     bin/classes-processed.jar
-libraryjars /usr/local/java/android-sdk/platforms/android-9/android.jar

-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*

-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>;
} 

And then you should sign and export your apk. 然后你应该签名并导出你的apk。 If you dont sign obfuscation does not work. 如果你不签名混淆不起作用。

The tutorial is not up to date. 该教程不是最新的。 The proguard-project.txt is the correct proguard config file (which used to be "proguard.cfg" ). proguard-project.txt是正确的proguard配置文件(以前是“proguard.cfg”)。

I don't know though what the proguard-android.txt is supposed to be... In my project.properties it only says: 我不知道proguard-android.txt应该是什么...在我的project.properties中它只说:

"proguard.config=proguard-project.txt" (proguard.project.txt is in the same folder as the the properties file) and it works... “proguard.config = proguard-project.txt”(proguard.project.txt与属性文件位于同一文件夹中),它可以工作......

To enable ProGuard so that it runs as part of an Ant or Eclipse build, set the proguard.config property in the project.properties file. 要启用ProGuard以使其作为Ant或Eclipse构建的一部分运行,请在project.properties文件中设置proguard.config属性。

proguard.config=proguard.cfg

Add this to a file called proguard.cfg to your projects root folder. 将此文件添加到名为proguard.cfg的文件中,添加到项目根文件夹中。 It' s the basic configuration from the example (proguard-android.txt). 这是示例中的基本配置(proguard-android.txt)。

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

-dontoptimize
-dontpreverify

-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}


-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

-dontwarn android.support.**

Then run your application. 然后运行您的应用程序

Proguard configuration is not easy especially when you have several libraries. Proguard配置并不容易,尤其是当您有多个库时。

See the documentation here Proguard and on the android developers page Android Proguard Description . 请参阅此处的文档Proguard和Android开发者页面上的Android Proguard说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM