具体可参考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. 开心菜鸟学习系列-----javascript(2)

    最小全局变量 :        1)每个javascript环境有一个全局对象,当你在任意的函数外面使用this的时候可以访问到,你创建的每一个全部变量都成了这个全局对象的属性,在浏览器中,方便起见, ...

  2. Android中图片的目录

    图片放在hdpi及在mdpi中的效果是不一样的 http://blog.csdn.net/loongggdroid/article/details/9469935

  3. Quartz.net Cron表达式

    由7段构成:秒 分 时 日 月 星期 年(可选)"-" :表示范围  MON-WED表示星期一到星期三"," :表示列举 MON,WEB表示星期一和星期三&qu ...

  4. 关于PowerShell中的命令的别名

    cmdlets的别名,有利于使用传统的cmd的方式 或者使用 bash的方式的人员,更加方便的使用使用频率较高的命令. 以下是从 别名中获取的内置的别名. PS C:\> Get-Alias * ...

  5. CPU的物理限制

    Quote from Solidot 密歇根大学的Igor Markov在上周的<自然>期刊上发表了一篇文章,谈论了CPU面临的基本物理限制.有学者曾估计预言CPU晶体管数目和性能增长的摩 ...

  6. bzoj3431 [Usaco2014 Jan]Bessie Slows Down

    Description [Brian Dean, 2014] Bessie the cow is competing in a cross-country skiing event at the wi ...

  7. Python 协程(gevent)

    协程,又叫微线程,协程是一种用户态的轻量级线程. 协程拥有自己的寄存器上下文和栈.协程调度切换时,将寄存器上下文和栈保存到其他地方,在切回来的时候,恢复先前保存的寄存器上下文和栈.因此: 协程能保留上 ...

  8. Unity UI和引用的管理中心

    我们来谈谈Unity的UI, 通常会写一些UI页面,当A页面需要去操作B页面的时候. 至少要获取B页面的引用吧! 一般新人都会在组件的写一个public GameObject UIB页面的属性, 然后 ...

  9. android:launchMode="singleTask" 与 onNewIntent(Intent intent) 的用法

    最近项目开发中用到了android:launchMode="singleTask" 和 onNewIntent(Intent intent)两个特性,现总结一下经验: androi ...

  10. COCOS2D-X 不反复随机数

    srand(time(NULL)); int a[5]; for(int i=0;i<5;i++) { a[i]=CCRANDOM_0_1()*5; } srand放在循环外面