Java编写的代码很容易被反编译,但是可以使用proguard来尽最大努力来保护我们的代码,proguard具体使用可以参考官方文档(http://proguard.sourceforge.net/),现在就把我的配置写下来(实际使用中),以供参考
1.到http://proguard.sourceforge.net/下载proguard
2.准备好要的jar包,我在这里举例是 Yulore_yellowSDK.jar
3.解压proguard,双击 bin目录下的proguardgui.bat,打开Proguard图形化窗口,如下图所示:
Proguard 图形化窗口:
选择混淆配置文件proguard_common.cfg,如下:
选择完成之后,点击 Next,选择 要混淆的jar文件,如下:
点击 Add input 按钮,选择 待混淆的jar文件,如下:
同理,点击 Add output 选择混淆生成jar文件的保存路径,如下:
完成之后,点击 Next ,进入如下界面:
基本上不用修改,直接 点击 Next 按钮,进入下一个界面
不用修改,直接 点击 Next
也不用做任何修改,直接点击 Next
不用做任何修改,直接点击 Next
来到这个界面,点击Process 开始 代码混淆,如下:
混淆完成后的界面,如下:
混淆配置文件 proguard_common.cfg
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-dontshrink
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-libraryjars D:/proguard_Test/proguard_libs/map.jar
-libraryjars D:/proguard_Test/proguard_libs/core.jar
-libraryjars D:/proguard_Test/proguard_libs/geocoder_location.jar
-libraryjars D:/proguard_Test/proguard_libs/android.jar
-libraryjars D:/proguard_Test/proguard_libs/annotations.jar
-libraryjars D:/proguard_Test/proguard_libs/android-support-v4.jar
-libraryjars D:/proguard_Test/proguard_libs/fastJson.jar
-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 public class * extends android.view.View
-keep public class * extends android.app.Application
-keep class com.yulore.yellowsdk.view.** { *; }
-keep class com.yulore.yellowsdk.cache.** { *; }
-keep class com.yulore.yellowsdk.entity.** { *; }
-keep class com.yulore.yellowsdk.http.** { *; }
-keep class com.yulore.yellowsdk.util.APIKeyFactory
-keepclasseswithmembers class * {
native <methods>;
}
-keepclasseswithmembers class * {
public static <methods>;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers 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 *;
}
-dontwarn com.mapabc.mapapi.route.**
-keep class com.mapabc.mapapi.map.** { *; }
-keep class com.mapabc.mapapi.route.** { *; }
-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-keep class android.support.v4.app.** { *; }
-keep class android.support.v4.view.** { *; }
-keep public class * extends android.support.v4.**
-keepclassmembers class * {
public <init>(org.json.JSONObject);
}
-keep class com.alibaba.fastjson.** { *; }
依赖的jar包目录:
混淆过程中有任何问题,可以参考以下网站:
http://docs.huihoo.com/proguard/manual/troubleshooting.html