通过eclipse对apk加密混淆的方法

论坛 期权论坛 脚本     
匿名网站用户   2020-12-20 14:50   32   0

为了防止其他人盗用自己的源码,在发布apk之前我们可以对源码进行加密,防止反编译。

1、对工程添加proguard.cfg文件,自定义要混淆的文件类型。

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-libraryjars libs/android-support-v4.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 com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames 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 *;
}

-libraryjars 代表工程的lib引用
-keep 代表要保留的源码类型,不做混淆
-keepclasseswithmembernames 代表要保留的类,不做混淆

定义好proguard.cfg后,把proguard.cfg加到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
*proguard.config=proguard.cfg*
# Project target.
target=android-21
android.library.reference.1=../../workspace/appcompat_v7

2、Eclipse中右键工程导出,添加已生成的keystore,或者新建keystore,加密导出。

这里写图片描述

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1136255
帖子:227251
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP