具体可参考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. hdu 六度分离

    http://acm.hdu.edu.cn/showproblem.php?pid=1869 #include <cstdio> #include <cstring> #inc ...

  2. HDU 3401 Trade(单调队列优化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3401 题意:炒股.第i天买入一股的价钱api,卖出一股的价钱bpi,最多买入asi股,最多卖出bsi股 ...

  3. PHP与C++的不同

    由于工作需要,需要学习一下PHP,由于3年的C++背景,在刚开始学习PHP的过程中,有些不习惯,经过一段时间的学习,总结了一些PHP与C++的不同. 1.应用场景 在谈两种语言不同的时候,首先需要了解 ...

  4. Javascript或jQuery方法产生任意随机整数

    方法1:javascritp方法 1 2 3 4 5 6 //随机数    function diu_Randomize(b,e){        if(!b && b!=0 || ! ...

  5. poj 3045 Cow Acrobats(二分搜索?)

    Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away a ...

  6. jquery.validate详解二

    五.常用方法及注意问题 1.用其他方式替代默认的SUBMIT $().ready(function() {  $("#signupForm").validate({         ...

  7. ZOJ 3329 One Person Game 带环的概率DP

    每次都和e[0]有关系 通过方程消去环 dp[i] = sigma(dp[i+k]*p)+dp[0]*p+1 dp[i] = a[i]*dp[0]+b[i] dp[i] = sigma(p*(a[i+ ...

  8. "git rm" 和 "rm" 的区别

    "git rm" 和 "rm" 的区别 FEB 3RD, 2013 | COMMENTS 这是一个比较肤浅的问题,但对于 git 初学者来说,还是有必要提一下的 ...

  9. linux中萌翻了的cowsay命令

    想要让你的linux萌翻吗? 首先需要安装cowsay软件 命令如下:sudo apt-get update;sudo apt-get install cowsay 然后对其输入命令,默认情况下,动物 ...

  10. XMLHttpRequest发送请求

    *open(method,url,async) *send(string)//在使用get请求的时候,是没有主体的,所有的信息都会拼在url当中,所以使用send的时候括号里的string可以为空!如 ...