android-android怎么实现只混淆自己的代码,而不混淆第3方jar包

 我来答
受司大人
2015-02-23 · 知道合伙人影视综艺行家
受司大人
知道合伙人影视综艺行家
采纳数:20262 获赞数:171845
毕业于浙江广厦,有一定的电脑专业基础和两年工作经验,读过相关书籍多本

向TA提问 私信TA
展开全部
当项目中有第3方jar包时,怎么实现混淆打包,而不对第3方包混淆
在项目中有第3方包时打包出错日志:

[2012-06-14 14:14:28 - humei_cc] Proguard returned with error code 1. See console

[2012-06-14 14:14:28 - humei_cc] Note: there were 2068 duplicate class definitions.

[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.datatransfer.DataProxy: can't find superclass or interface java.awt.datatransfer.Transferable

[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.datatransfer.NativeClipboard: can't find superclass or interface java.awt.datatransfer.Clipboard

[2012-06-14 14:14:28 - humei_cc] Warning: javax.activation.CommandInfo: can't find referenced class java.beans.Beans

[2012-06-14 14:14:28 - humei_cc] Warning: javax.activation.CommandInfo: can't find referenced class java.beans.Beans

[2012-06-14 14:14:28 - humei_cc] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslException

[2012-06-14 14:14:28 - humei_cc] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslException

[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.DataFlavor

[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.DataFlavor

………………………………………………………………………………中间部分省略

[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit

[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit

[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment

[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment

[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment

[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.datatransfer.NativeClipboard: can't find referenced class java.awt.datatransfer.Clipboard

[2012-06-14 14:14:28 - humei_cc] Warning: org.apache.harmony.awt.datatransfer.NativeClipboard: can't find referenced class java.awt.datatransfer.Clipboard

[2012-06-14 14:14:28 - humei_cc] Warning: there were 288 unresolved references to classes or interfaces.

[2012-06-14 14:14:28 - humei_cc] You may need to specify additional library jars (using '-libraryjars'),

[2012-06-14 14:14:28 - humei_cc] or perhaps the '-dontskipnonpubliclibraryclasses' option.

[2012-06-14 14:14:28 - humei_cc] java.io.IOException: Please correct the above warnings first.

[2012-06-14 14:14:28 - humei_cc] at proguard.Initializer.execute(Initializer.java:308)

[2012-06-14 14:14:28 - humei_cc] at proguard.ProGuard.initialize(ProGuard.java:210)

[2012-06-14 14:14:28 - humei_cc] at proguard.ProGuard.execute(ProGuard.java:85)

[2012-06-14 14:14:28 - humei_cc] at proguard.ProGuard.main(ProGuard.java:499)
我的proguard.cfg 文件时这样的

-optimizationpasses 5

-dontusemixedcaseclassnames

-dontskipnonpubliclibraryclasses

-verbose

-ignorewarnings

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

-libraryjars libs/bcprov-jdk15on-147.jar

-libraryjars libs/PanoramaGL.jar

-libraryjars libs/activation.jar

-libraryjars libs/additionnal.jar

-libraryjars libs/mail.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 * extends android.app.backup.BackupAgentHelper

-keep public class * extends android.preference.Preference

-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {

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 * {

public static **[] values();

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

}

-keep class * implements android.os.Parcelable {

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

}
已经尝试的方案:方案一: 加入-ignorewarnings 可以正常打包了。 能过滤掉警告信息。但是治标不治本,打好的包,在实际运行中用到过的第3方包类库时,均报空指针。方案二:不使用-ignorewarnings 添加-dontwarn java.awt.datatransfer.Transferable.** 警告信息并没有减少,打包会失败。
小猪睡枕头
2015-12-12 · TA获得超过266个赞
知道小有建树答主
回答量:260
采纳率:0%
帮助的人:124万
展开全部
以Android studio 工具举例,
如要指定不混淆的内容可以在项目根目录下编写proguard-rules.pro
举例:

-keep public class * extends android.app.Activity # 保持哪些类不被混淆

-keep public class com.android.vending.licensing.ILicensingService # 保持哪些类不被混淆

就是继承于你指定的类/你直接指定的类不被混淆,所以你先看看你第三方的jar的包名类目然后填上即可
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
wudkj
2016-01-05 · TA获得超过122个赞
知道答主
回答量:139
采纳率:0%
帮助的人:54.3万
展开全部
-libraryjars libs/gson-2.3.1.jar
上面那个是最基本的
-keep class **.R$* {*;}
不过有的类还是会被混淆,需要手动保持类不被混淆
有的第三方在自己的官网或者开发者平台会有混淆的代码,可以找找(比如一键分享就有)
http://sumile.cn/archives/988.html
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式