189 8069 5689

android混淆代码,android混淆代码aidl

什么是代码混淆?andriod和android-studio工程如何启用代码混淆功能

代码混淆有两种重要功能。其一,混淆代码。其二,优化代码。

创新互联长期为成百上千客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为肇东企业提供专业的网站制作、成都网站建设肇东网站改版等技术服务。拥有10余年丰富建站经验和众多成功案例,为您定制开发。

进行代码混淆的程序被称为代码混淆器(混淆工具)。进行代码混淆的意义主要在于对代码进行一定程度的加密。

在android 2.3之后,sdk中就已经集成了混淆器proguard(目录在sdk\tools\proguard),所以我们可以很方便的直接在工程中开启代码混淆。

eclipse android工程开启混淆功能,我们需要手动在项目文件.properties(我的是project.properties文件)中添加下面的代码

# 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

某些方式创建的项目中可能已经有如上两行了,只是默认被注释掉了,只要把proguard.config这一行解注释就好了。这样代码混淆功能就开启了,在打签名包时,项目会自动进行代码混淆。

如何混淆android代码以及注意事项

2.3SDK的两个新特点:

1.刚安装上2.3时,查看sdk目录,发现在\tools下新增了一文件夹“proguard”,如下图,我就在想是不是Google终于官方对proguard考虑进去了。理论上,对java的混淆都是可以的,但关键在于如何编写proguard的混淆脚本。

2.使用SDK2.3后,新建的工程下和之前相比,都会多了一个文件“proguard.cfg”。一打开,相当惊喜,这就是混淆所需的proguard脚本啊。

如下图:

其代码如下:

view plaincopy to clipboardprint?

-optimizationpasses 5

-dontusemixedcaseclassnames

-dontskipnonpubliclibraryclasses

-dontpreverify

-verbose

-optimizations

!code/simplification/arithmetic,!field/*,!class/merging/*

-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 com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {

native ;

}

-keepclasseswithmembernames class * {

public (android.content.Context, android.util.AttributeSet);

}

-keepclasseswithmembernames class * {

public (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 *;

}

-optimizationpasses 5

-dontusemixedcaseclassnames

-dontskipnonpubliclibraryclasses

-dontpreverify

-verbose

-optimizations

!code/simplification/arithmetic,!field/*,!class/merging/*

-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 com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {

native ;

}

-keepclasseswithmembernames class * {

public (android.content.Context, android.util.AttributeSet);

}

-keepclasseswithmembernames class * {

public (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 *;

}

从脚本中可以看到,混淆中保留了继承自Activity、Service、Application、BroadcastReceiver、ContentProvider等基本组件。

并保留了所有的Native变量名及类名,所有类中部分以设定了固定参数格式的构造函数,枚举等等。(详细信息请参考\examples中的例子及注释。)

好了,进行得差不多了,下面就来看看如何真正的生成混淆APK吧。这儿又得提醒一下,SDK新的特性在文档里都是有的,所以文档很重要。

查看SDK2.3的文档,在路径“/docs/guide/developing/tools/proguard.html”的“Enabling

ProGuard ”中是这样描述的:

To enable ProGuard so that it runs as part of an Ant or Eclipse build, set

the proguard.config property in the /default.properties file. The path can be an

absolute path or a path relative to the project's root.

好的,那就这样做吧。

在工程的"default.properties"中添加这样一句话“proguard.config=proguard.cfg”,如下图:

这样就已经设置好ADT的混淆操作了。接下来就是正常的打包和签名了。。

下图是我混淆SDK Demo中自带的Notepad效果图:

注意要点:

1.混淆以后的包会比混淆前的包小一点,一定要注意这点.

如果混淆不成功,请在第2步,将proguard.config=proguard.cfg修改为proguard.config=E:\Mobile_Develop\Google_Android\publicGoldenBeach_new\proguard.cfg这种类似的用绝对路径,请注意绝对路径中的文件夹名不能含有空格,如果有空格请替换为"_".

2.android在用proguard混淆时,一般情况下使用系统自带的配置文件就可以保持大部分外部需要引用的类,比如Activity,view扩展等等,但是有些情况下一些引入的外部lib,如果被混淆也会出现各种各样的问题,如果不想混淆这些包,就要加上

-keep class packagename.** {*;}

这样就能完整保持原有class了

android 代码混淆算法有哪些

根据 SDK 的版本不同有 2 中不同的代码混淆方式,以上的 proguard.cfg 参数详解中所涉及到的信息是在较低版本 SDK 下的混淆脚本,事实上在高版本的 SDK 下混淆的原理和参数也与低版本的相差无几,只是在不同 SDK 版本的环境下引入混淆脚本的方式有所不同。具体方法如下:

低版本 SDK 下,项目中同时包含 proguard.cfg 和 project.properties 文件,则只需在 project.properties 文件末尾添加 proguard.config=proguard.cfg 再将项目 Export 即可。

高版本 SDK 下,项目中同时包含 proguard-project.txt 和 project.properties 文件,这时需要在 proguard-project.txt 文件中进行如下信息的配置,然后再将项目 Export 即可。下面以真实的文件进行演示说明。

复制代码

# 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

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.

target=android-16

复制代码

以上的配置信息即是 project.properties 文件中内容,蓝色文字为我们在代码混淆过程中需要添加的配置信息,其中:sdk.dir 为你在当前机器上 SDK 的安装路径。如果想保留某个包下的文件不被混淆,可以在 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

#

# Add any project specific keep options here:

-dontwarn com.cnki.android.cnkireader.**

-keep class com.cnki.android.cnkireader.** { *; }

# 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 *;

#}

复制代码

android studio怎么混淆代码

1,在build.grandle添加,其中规则写在proguard-rules.pro中,也可以自定义一个文件,将其代替,比如eclipse常用的 proguard-project.txt

buildTypes {

release {

signingConfig signingConfigs.release

minifyEnabled true

proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘

}

}

2,在proguard-rules.pro中加入以下代码,基本可以涵盖所有

-optimizationpasses 5 # 指定代码的压缩级别

-dontusemixedcaseclassnames # 是否使用大小写混合

-dontpreverify # 混淆时是否做预校验

-verbose # 混淆时是否记录日志

-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* # 混淆时所采用的算法

-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 # 保持哪些类不被混淆

-keepclasseswithmembernames class * { # 保持 native 方法不被混淆

native methods;

}

-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.app.Activity { # 保持自定义控件类不被混淆

public void *(android.view.View);

}

-keepclassmembers enum * { # 保持枚举 enum 类不被混淆

public static **[] values();

public static ** valueOf(java.lang.String);

}

-keep class * implements android.os.Parcelable { # 保持 Parcelable 不被混淆

public static final android.os.Parcelable$Creator *;

}


文章题目:android混淆代码,android混淆代码aidl
浏览地址:http://cdxtjz.cn/article/dsdicgi.html

其他资讯