[英]How can I obfuscate my code in Eclipse? (Android)
我是Android应用程序的新手。 我编写了一个应用程序,需要在eclipse中对其进行模糊处理。 我尝试使用以下教程:
http://developer.android.com/tools/help/proguard.html
但是当我创建我的项目时,eclipse没有产生任何“proguard.cfg”文件。 我只有一个“project.properties”取消注释以下行。
proguard.config = $ {} sdk.dir /tools/proguard/proguard-android.txt:proguard-project.txt
我把{sdk.dir}路径改为sdk。 我也没有progurd-android.txt。 对于初学者如何在android中混淆代码是否有任何明确的步骤? 或者你有可能为我解释一下吗? 感谢帮助。
首先,你应该在project.ptoperties上注释掉这一行:
然后你应该把你的规则编写到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>;
}
然后你应该签名并导出你的apk。 如果你不签名混淆不起作用。
该教程不是最新的。 proguard-project.txt是正确的proguard配置文件(以前是“proguard.cfg”)。
我不知道proguard-android.txt应该是什么...在我的project.properties中它只说:
“proguard.config = proguard-project.txt”(proguard.project.txt与属性文件位于同一文件夹中),它可以工作......
要启用ProGuard以使其作为Ant或Eclipse构建的一部分运行,请在project.properties
文件中设置proguard.config属性。
proguard.config=proguard.cfg
将此文件添加到名为proguard.cfg
的文件中,添加到项目根文件夹中。 这是示例中的基本配置(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.**
然后运行您的应用程序
Proguard配置并不容易,尤其是当您有多个库时。
请参阅此处的文档Proguard和Android开发者页面上的Android Proguard说明 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.