网上好多混淆教程,但是看别人的总不如看自己的,而且比较喜欢傻瓜式教程...所以还是自己倒腾好了
先是混淆前后的Demo效果图对比
源码:
①混淆前
②混淆后
** Test之所以没被混淆是我特意做了测试 : 指定某个类不被混淆
MainActivity之所以没被混淆是因为Android本身就规定了Activity,Service是没法被混淆的(如果这都混淆了那程序自己运行起来也麻烦死了,生命周期都乱成一团)
至于是不是四大组件全都不能被混淆就不清楚了,测试一下即可得知
1:工程下有两个文件
project.properties是开启混淆的
proguard-project.txt 是主要是你的混淆需求都会写在这里
2:开启混淆
在project.proerties中
正常情况下
该文件只会有第一句 target=android-18
如果需要混淆则需加上后面那句
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
这样在打包的时候会自动进行混淆
3:proguard-project.txt
该文件的内容有一部分是Google自带的
# 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 *;
#}
这一部分的效果是 : 对你的工程进行混淆 (前提是 你的工程完全没用到第三方包 如果有第三方包 需要在此基础上进行增加)
4:语法 (效果是 例如对某个特定类指定不混淆)
-keep class com.example.httpdemo.Test {*;}
其中 class com.example.httpdemo.Test 是你的类的绝对路径
--------------------------------------------------
目前只测试了这些 都写上来了 以后有新用的再增
--------------------------------------------------
参考链接
http://blog.csdn.net/lovexjyong/article/details/24652085