具体可参考http://proguard.sourceforge.net/manual/examples.html#library

1、找到android的adt目录下的 D:\soft\adt-bundle-windows-x86\sdk\tools\proguard 文件夹,这个文件夹中有个examples文件夹,打开可看到 android.pro 这是个android混淆代码的demo,你可以完全复制里面的东西,把里面对应的东西改成自己的,然后再添加不要混淆的自己的 类接口等信息 保存为  .pro 文件

2、找到  D:\soft\adt-bundle-windows-x86\sdk\tools\proguard\bin 目录下的 proguardgui.bat 文件双击 会弹出一个图形界面选择左上角的 ProGuard 按钮,然后再右下角有个 Load configuration... 点击选择你的 .pro 文件导入

3、点击图形界面的第二个按钮 Input/Output  添加你要混淆的 jar 或文件夹或其他,对应的也要选择好输出文件对应的东西

4、设置完成后找到左边菜单栏的 Process,选中,然后再页面的右下角找到 process 点击即可完成。

5、 主要混淆后的包一定要测试下。

示例混淆配置文件如下:

#
# This ProGuard configuration file illustrates how to process Android
# applications.
# Usage:
# java -jar proguard.jar @android.pro
#
# If you're using the Android SDK (version 2.3 or higher), the android tool
# already creates a file like this in your project, called proguard.cfg.
# It should contain the settings of this file, minus the input and output paths
# (-injars, -outjars, -libraryjars, -printmapping, and -printseeds).
# The generated Ant build file automatically sets these paths. # Specify the input jars, output jars, and library jars.
# Note that ProGuard works with Java bytecode (.class),
# before the dex compiler converts it into Dalvik code (.dex).

-injars IPS.jar #要混淆的jar包名,注意路径。只写jar包名,则jar包和本混淆配置文件在同一个路径下。
#-injars libs
-outjars IPSPro.jar #输出的混淆后的jar包 -libraryjars F:/adt-bundle-windows-x86_64-20140321/sdk/platforms/android-19/android.jar #依赖的jar包也需导入,否则会出现找不到类的错误
#-libraryjars /usr/local/android-sdk/add-ons/google_apis-7_r01/libs/maps.jar
# ... # Save the obfuscation mapping to a file, so you can de-obfuscate any stack
# traces later on. #-printmapping bin/classes-processed.map # You can print out the seeds that are matching the keep options below. #-printseeds bin/classes-processed.seeds # Preverification is irrelevant for the dex compiler and the Dalvik VM. -dontpreverify # Reduce the size of the output some more. -repackageclasses ''
-allowaccessmodification # Switch off some optimizations that trip older versions of the Dalvik VM. -optimizations !code/simplification/arithmetic # Keep a fixed source file attribute and all line number tables to get line
# numbers in the stack traces.
# You can comment this out if you're not interested in stack traces. -renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable # RemoteViews might need annotations. -keepattributes *Annotation* # Preserve all fundamental application classes. -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 # Preserve all View implementations, their special context constructors, and
# their setters. -keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
} # Preserve all classes that have special context constructors, and the
# constructors themselves. -keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
} # Preserve all classes that have special context constructors, and the
# constructors themselves. -keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
} # Preserve the special fields of all Parcelable implementations. -keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
} # Preserve static fields of inner classes of R classes that might be accessed
# through introspection. -keepclassmembers class **.R$* {
public static <fields>;
} # Preserve the required interface from the License Verification Library
# (but don't nag the developer if the library is not used at all). -keep public interface com.android.vending.licensing.ILicensingService -dontnote com.android.vending.licensing.ILicensingService # The Android Compatibility library references some classes that may not be
# present in all versions of the API, but we know that's ok. -dontwarn android.support.** # Preserve all native method names and the names of their classes. -keepclasseswithmembernames class * {
native <methods>;
} # Preserve the special static methods that are required in all enumeration
# classes. -keepclassmembers class * extends java.lang.Enum {
public static **[] values();
public static ** valueOf(java.lang.String);
} # Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
# You can comment this out if your application doesn't use serialization.
# If your code contains serializable classes that have to be backward
# compatible, please refer to the manual. -keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
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();
} # Your application may contain more items that need to be preserved;
# typically classes that are dynamically created using Class.forName: -keep public class com.dkdh.ips.StepDetector{
# public <fields>;
public <methods>;
}
-keep public class com.dkdh.ips.SensorFusion{
# public <fields>;
public <methods>;
}
#不混淆异常,内部类等
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
SourceFile,LineNumberTable,*Annotation*,EnclosingMethod # -keep public class com.dkdh.ips.Util{
# public <fields>;
# public <methods>;
# }
-keep class com.dkdh.ips.IPSSensorManager{
public static boolean getRotationMatrix(float[],float[],float[],float[]);#只保留该方法不混淆,其他所有全部混淆
# public <fields>;
#public <methods>;
}
# -keep class com.dkdh.ips.SensorFusion.calculateFusedOrientationTask{
# public <fields>;
# public <methods>;
# }
# -keep public interface mypackage.MyInterface
# -keep public class * implements mypackage.MyInterface

出现Error: The output jar is empty. Did you specify the proper '-keep' options?错误,

是因为混淆的代码没有一个入口,也就是说,这个程序或者jar包被全部混淆了,外部没有任何一个地方可以正常调用到它,换句话说就是“混淆出来的东西没法用”。

混淆时,要暴露的接口、变量和方法不能混淆,一般是public修饰不要混淆。

Android jar包混淆的更多相关文章

  1. jar包混淆和防反编译工具proguard使用简介

    平时都是用java语言做开发,特殊情况下,需要对编译出的jar包混淆,防止被轻易的反编译出来看到源码,用的proguard工具,下面简单记录一下工具使用过程. 1.下载程序包,可以去https://w ...

  2. ant打包和jar包混淆

    Ant是一种基于Java的build工具.相似于c语言中的makefile,这里做一记录.方便后面查看. <?xml version="1.0" encoding=" ...

  3. 混淆Android JAR包的方法

    http://blog.csdn.net/vurtne_ye/article/details/35599491 1)导出jar包 如何在eclipse上Android工程中导出jar包?google, ...

  4. Android jar包的导出和使用

    一.工程打成JAR包. 1.       eclipse下有一工程JsnTxJar,右键工程名选择Export. 选择Java->JAR file 下图所示左边一栏只勾选src,右边一栏都不用勾 ...

  5. Android JAR包、Library项目

    [JAR包] android引入JAR包,打包成JAR包,打包成Library项目,导入Library项目 (1)项目导入JAR包:1.在项目目录里建立一个libs目录,将外部jar包拷贝在里面.2. ...

  6. Android中使用proguardgui混淆jar包

    本文章的前提条件是,读者已经掌握了正确导出jar包的技能. 1.拷贝Android项目中"proguard.cfg"文件到你指定的位置,并改名为"proguard.pro ...

  7. android studio gradle 打jar 包 (混淆+第三方库包)

    将依赖的第三方库打包进自己的jar包 1.先将第三方的库包拿到,然后添加jar包到项目的libs. 2.项目的build.gradle脚本添加下面的task: task buildJar(depend ...

  8. 【Android】jar包Proguard混淆方法

    本文章的前提条件是,读者已经掌握了正确导出jar包的技能. 1.拷贝Android项目中“proguard.cfg”文件到你指定的位置,并改名为“proguard.pro”,此步是为proguardg ...

  9. 在Eclipse上打包并使用Proguard工具混淆jar包

    近期由于工作须要,学习到了Android jar包的打包与混淆. 之前觉得还是非常easy的,可是自己深入研究下,发现还是有一些东西须要注意的,并且自己也踩了一些坑,在这里写下供同僚们借鉴借鉴. 转载 ...

随机推荐

  1. VirtualBox 修改UUID实现虚拟硬盘复制

    最近用VirtualBox创建虚拟机,复制了一个虚拟硬盘之后,直接添加到列表,发现无法使用....提示为UUID已经被使用. 查找了一下解决方法:一般的介绍说操作方法为: 在命令行中,打开Virtua ...

  2. GestureDetector和SimpleOnGestureListener的使用教程

    1. 当用户触摸屏幕的时候,会产生许多手势,例如down,up,scroll,filing等等,我们知道View类有个View.OnTouchListener内部接口,通过重写他的onTouch(Vi ...

  3. esxi5.5 安装,虚拟机复制

    尝试在vmware workstation上安装hadoop,感觉太慢了. 好在家里的台式机配置还可以,所以就想在它上面虚拟出几台服务器出来. 台式机配置如下: 虚拟出来三个应该没问题了吧. 第一步, ...

  4. 在Struts2中集成Spring详细讲解

    Spring的官方定义是:一个轻量级的IoC和Aop容器框架,它使用了一种叫做依赖注入的技术. 所谓依赖注入,就是指将创建对象以及协议依赖对象之间合作的责任从对象自身中转移到"工厂" ...

  5. GitHub使用说明

    登陆https://github.com/,并注册账号 从如下地址下载windows客户端:https://msysgit.googlecode.com/files/Git-1.8.4-preview ...

  6. uva10245-The Closest Pair Problem(平面上的点分治)

    解析:平面上的点分治,先递归得到左右子区间的最小值d,再处理改区间,肯定不会考虑哪些距离已经大于d的点对,对y坐标归并排序,然后从小到大开始枚举更新d,对于某个点,x轴方向只用考虑[x-d,x+d]( ...

  7. Android --- 字符串\n的换行问题

    我的一段文字"测试文本\n测试文本\n测试文本\n测试文本\n测试文本\n测试文本\n". 该段文字放在一个txt文本内. 我用流读取后,显示在一个TextView里. 我期望的显 ...

  8. python高级编程(第12章:优化学习)2

    #优化策略 #3个原则 """ 1a:寻找其他原因:确定第三方服务器或资源不是问题所在 2a:度量硬件:确定资源足够用 3a:编写速度测试:创建带有速度要求的场景 &qu ...

  9. redis简单配置

    由于前段时间使用Kestrel,同时要操作Memcached及时更新缓存,又要操作database,持久化数据. 貌似Redis既可以当Cache又可以当Queue!于是,今天开始研究Redis! 一 ...

  10. sprig——jar包

    Struts. Hibernate.Spring这类的框架给我们开发带来非常大的好处,让我们更加快速.有效的开发.所以我们在开发中通常都会用到各种框架,每个框架 都有很多jar包,每个jar都有各自不 ...