- android app的 混淆打包,详细教程见app混淆打包教程
- 根据以上的教程,我也给我的app做了一个混淆打包,反编译之后,发现的确混淆成功,并且运行正常。
- 我的app里面的代码比较简单,用到了第三方jar只有gson.
- 于是我的
proguard-project.txt
是这样的:
# 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 *;
#}
#######################################################
################gson##################
-libraryjars libs/gson-2.2.1.jar
-keep class com.google.gson.** {*;}
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
-keep class com.google.gson.examples.android.model.** { *; }
-keep class com.google.** {
<fields>;
<methods>;
}
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
-dontwarn com.google.gson.**
################common###############
-keep class com.duck.smsCHeck.bean.** {*;}
- 我的
project.properties
是这样的
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-20
android.library.reference.1=../appcompat_v7
只有这两个文件配置好了,然后就是右键导出为android app。一路next,添加或生成一个
keystore
文件这样就生成了一个混淆过的apk文件。附上我的导出之后的工程。导出之后的工程
- 顺便介绍一下工程的内容。主要是我之前的一个需求:短信验证的校验。
- 主要逻辑:发送请求给第三方平台(我这里用的是云之讯),然后,请求正确,手机就会收到一个验证码短信。读取该短信,判断其中验证码与生成的验证码是否相同,如果相同,验证通过。其他任何情况,验证不通过。然后,删除该验证码短信。(5.0以后的手机不能完成这一步).
- 里面的代码就不解释了,和上一篇相同。这里只是在之前的工程的基础上做了一个混淆打包。
- 关于如何将部分java代码导出生成混淆过的jar,这个还没有弄过,在搜索中…..