Android代码混淆及项目发布步骤记录

本来整理了一份Android项目混淆与发布的文档,突然想到何不写篇博客,分享一下呢,如是便有了本文。

Android代码混淆及项目发布步骤记录

一、清理代码中的调试信息,如Log、System.out

二、在清单文件中修改版本为当前版本,如果需要更新数据库,则需要在配置类或配置文件中修改程序数据库版本。

三、在清单文件中将项目的debugable设置为false

四、创建签名证书keystore文件

五、在项目中的project.properites文件中添加语句proguard.config=proguard-project.txt来指定混淆规则文件

六、配置proguard-project.txt文件

七、如果项目引用了Library Project,则Eclipse应该会在project.properties文件中自动生产android.library.reference.1..n=../LibraryProjectName

八、如果项目中包含svntmp(通常位于项目的bin文件夹下),在打包时应及时删除,否则会导致打包失败。

九、项目打包,安装测试(最好是使用现有生成包进行升级测试)

附:示例proguard-project.txt文件及相应说明:

# This is a configuration file for ProGuard.

# http://proguard.sourceforge.net/index.html#manual/usage.html

# Optimizations: If you don't want to optimize, use the

# proguard-android.txt configuration file instead of this one, which

# turns off the optimization flags. Adding optimization introduces

# certain risks, since for example not all optimizations performed by

# ProGuard works on all versions of Dalvik. The following flags turn

# off various optimizations known to have issues, but the list may not

# be complete or up to date. (The "arithmetic" optimization can be

# used if you are only targeting Android 2.0 or later.) Make sure you

# test thoroughly if you go this route.

-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*

-optimizationpasses 5

-allowaccessmodification

-dontpreverify

#-dontoptimize

# The remainder of this file is identical to the non-optimized version

# of the Proguard configuration file (except that the other file has

# flags to turn off optimization).

-dontusemixedcaseclassnames

-dontskipnonpubliclibraryclasses

-keepattributes Signature

-verbose

-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

-keepattributes *Annotation*

-keep public class com.google.vending.licensing.ILicensingService

-keep public class com.android.vending.licensing.ILicensingService

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native

-keepclasseswithmembernames class * {

native <methods>;

}

# keep setters in Views so that animations can still work.

# see http://proguard.sourceforge.net/manual/examples.html#beans

#-keepclassmembers public class * extends android.view.View {

#   void set*(***);

#   *** get*();

#}

# We want to keep methods in Activity that could be used in the XML attribute onClick

-keepclassmembers class * extends android.app.Activity {

public void *(android.view.View);

}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations

-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$* {

*;

}

# The support library contains references to newer platform versions.

# Don't warn about those in case this app is linking against an older

# platform version. We know about them, and they are safe.

-keep class * extends android.view.View{*;}

-keep class * extends android.app.Dialog{*;}

-keep class * implements java.io.Serializable{*;}

#-ignorewarnings

-libraryjars libs/locSDK_4.1.jar

-libraryjars libs/pinyin4j-2.5.0.jar

-libraryjars libs/libammsdk.jar

-libraryjars libs/WebtrendsAndroidClientLib.jar

#-libraryjars libs/afinallib.jar

#-libraryjars libs/stickylistheaders_lib.jar

-keep class android.support.v4.** {*;}

-keep class com.emilsjolander.** {*;}

-keep class org.kobjects.** {*;}

-keep class org.kxml2.** {*;}

-keep class org.xmlpull.** {*;}

-keep class net.tsz.** {*;}

-keep class com.hp.** {*;}

-keep class com.baidu.** {*;}

-keep class net.sourceforget.** {*;}

-keep class com.tencent.** {*;}

-dontwarn demo.**

-keep class demo {*;}

-keep class com.wly.xxx.bean.** {*;}

-keep class com.wly.xxx.tool.DbModelUtils{*;}

-keep class com.wly.xxx.tool.JsonUtils{*;}

-keep class com.wly.xxx.activity.InsuranceQuotesActivity

-keep public class com.wly.xxx.activity.InsuranceQuotesActivity$MyJavaScriptInterface

-keep public class * implements com.wly.xxx.activity.InsuranceQuotesActivity$MyJavaScriptInterface

-keepclassmembers class com.wly.xxx.activity.InsuranceQuotesActivity$MyJavaScriptInterface {

public *;

private *;

}

文件说明:

0.以上文件拷贝自笔者现在开发的项目,出于项目保护的目的,已将工程包名替换com.wly.xxx,读者可以根据自己的项目加以修改!

1.蓝色内容具有通用性质,可以复制黏贴;

2.橙色内容用于指定程序中用到的jar文件(可以看到引用的Library Project不需包含,因为他们已经在project.properties文件中指定了)。

3.红色内容用于表示保留(不混淆)引用的jar包中的内容。

4.草绿色内容用于表示保留本地的bean文件下的实体类不被混淆。

5.紫色内容用于表示保留本地涉及反射的类不被混淆。

6.绿色内容用于特别处理Web JS与本地原生组件之间的调用过程不被混淆

Android代码混淆及项目发布方法记录的更多相关文章

  1. Android代码混淆和项目宣布步骤记录器

    原本放在一起Android项目与发布的文件相混淆.我突然想到,为什么不写博客,分享.有这篇文章的情况下,. Android代码混淆及项目公布步骤记录 一.清理代码中的调试信息,如Log.System. ...

  2. Android代码混淆官方实现方法

    首先查看一下 “project.properties” 这个文件: # This file is automatically generated by Android Tools.# Do not m ...

  3. Android 代码混淆配置总结

    一.前言 为何需要混淆呢?简单的说,就是将原本正常的项目文件,对其类,方法,字段,重新命名,a,b,c,d,e,f…之类的字母,达到混淆代码的目的,这样反编译出来,结构乱糟糟的,看了也头大. 另外说明 ...

  4. Android 代码混淆 混淆方案

    本篇文章:自己在混淆的时候整理出比较全面的混淆方法,比较实用,自己走过的坑,淌出来的路.请大家不要再走回头路,可能只要我们代码加混淆,一点不对就会导致项目运行崩溃等后果,有许多人发现没有打包运行好好地 ...

  5. Android 代码混淆规则

    1. Proguard介绍 Android SDK自带了混淆工具Proguard.它位于SDK根目录toolsproguard下面.ProGuard是一个免费的Java类文件收缩,优化,混淆和预校验器 ...

  6. Android 代码混淆

    什么是代码混淆 Java 是一种跨平台的.解释型语言,Java 源代码编译成中间”字节码”存储于 class 文件中.由于跨平台的需要,Java 字节码中包括了很多源代码信息,如变量名.方法名,并且通 ...

  7. 大公司怎么做Android代码混淆的?

    3月17日,网易资深安全工程师钟亚平在安卓巴士全球开发者论坛上做了<安卓APP逆向与保护>的演讲.其中就谈到了关于代码混淆的问题.现摘取部分重点介绍如下:   Java代码是非常容易反编译 ...

  8. Android 代码混淆、第三方平台加固加密、渠道分发 完整教程(图文)

    第一步:代码混淆(注意引入的第三方jar) 在新版本的ADT创建项目时,混码的文件不再是proguard.cfg,而是project.properties和proguard-project.txt. ...

  9. Android 代码混淆 防止反编译

    为了防止代码被反编译,因此需要加入混淆.混淆也可以通过第三方进行apk混淆,也可以用android中的proguard进行混淆. 混淆步骤: 1.配置混淆文件,名字可以随意,在这里使用proguard ...

随机推荐

  1. Linux指令od和hexdump

    Linux指令:od (octal dump) 示例用法:od -c hello Linux指令:od od命令用户通常使用od命令查看特殊格式的文件内容.通过指定该命令的不同选项可以以十进制.八进制 ...

  2. Java NIO2 File API介绍

    Introduction to the Java NIO2 File API GitHub NIO2中的文件API是Java 7附带的Java平台的主要新功能之一,特别是新的文件系统API的一个子集以 ...

  3. ServiceModel 元数据实用工具 (Svcutil.exe)

    ServiceModel 元数据实用工具用于依据元数据文档生成服务模型代码,以及依据服务模型代码生成元数据文档 一.SvcUtil.exe ServiceModel 元数据实用工具可在 Windows ...

  4. C#转义字符(好记性不如烂笔头)

    C#转义字符: ·一种特殊的字符常量:·以反斜线"\"开头,后跟一个或几个字符.·具有特定的含义,不同于字符原有的意义,故称“转义”字符.·主要用来表示那些用一般字符不便于表示的控 ...

  5. PAT 天梯赛 L1-022. 奇偶分家 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-022 AC代码 #include <iostream> #include <cstdio&g ...

  6. return false 和 return true

    常规用法 在普通函数中:return 语句终止函数的执行,并返回一个指定的值给函数调用者,一般会用一个变量接收这个返回值再进行其它处理.如果未指定返回值,则返回 undefined 其中,返回一个函数 ...

  7. SpringBoot服务器压测对比(jetty、tomcat、undertow)

    1.本次对比基础环境信息如下: springboot版本1.5.10 centos虚机4c6G,版本7.4 centos实机2u16c40G,版本7.4,虚机运行在实机上 ab版本2.3 jprofi ...

  8. 转换数据库连接池为hikaricp

      hikaricp号称是最快的,今天转换过来试试 1.修改配置文件 <!-- Hikari Datasource --> <bean id="dataSource&quo ...

  9. vim终端复制_不开启xterm_clipboard的解决方式

    后来发现了另外的方法,比这个更好==> 完美解决vim在终端不能复制的问题 http://www.cnblogs.com/cheerupforyou/p/6958695.html 使用xsehl ...

  10. redhat6.8链路聚合

    centos 6.X   聚合链路 0.查看NetworkManager服务,停止NetworkManager服务.不做这一步很可能出问题          service NetworkManage ...