Afinal 混淆打包报错的解决方法

纠结了好几天的问题.项目中导入了Afinal的jar包,在混淆打包的时候,一直报错.
org.eclipse.core.runtime.CoreException: Proguard returned with error code 1. See console
	at com.android.ide.eclipse.adt.internal.project.ExportHelper.exportReleaseApk(ExportHelper.java:301)
	at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.doExport(ExportWizard.java:305)
	at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.access$0(ExportWizard.java:234)
	at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard$1.run(ExportWizard.java:219)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: Proguard Error 1

      You should check if you need to specify additional program jars. 
Warning: there were 81 unresolved references to classes or interfaces. 
         You may need to specify additional library jars (using '-libraryjars'). 
Error: Please correct the above warnings first.
	at com.android.ide.eclipse.adt.internal.build.BuildHelper.runProguard(BuildHelper.java:590)
	at com.android.ide.eclipse.adt.internal.project.ExportHelper.exportReleaseApk(ExportHelper.java:265)
	... 4 more

为了找到根本原因,就把Afinal相关的资源删掉了, 打包,没有出现问题了.但是,把Afinal的资源添加上之后,打包又报错了.好吧,那就从混淆代码开始吧.

1.Afinal 的混淆操作.

-libraryjars libs/Afinal-0.3.4.jar 
-dontwarn net.tsz.afinal.** 
-keep class net.tsz.afinal.** { *; } 
-keep public class * extends net.tsz.afinal.**  
-keep public interface net.tsz.afinal.** {*;}
-keepattributes Signature
-keepattributes *Annotation* 

在proguard.cfg 添加上上面的内容,打包时,不混淆Afinal 的jar包.执行打包操作,结果仍然报错.


2.报错信息

org.eclipse.core.runtime.CoreException: Proguard returned with error code 1. See console
	at com.android.ide.eclipse.adt.internal.project.ExportHelper.exportReleaseApk(ExportHelper.java:301)
	at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.doExport(ExportWizard.java:305)
	at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.access$0(ExportWizard.java:234)
	at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard$1.run(ExportWizard.java:219)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: Proguard Error 1

      You should check if you need to specify additional program jars. 
Warning: there were 81 unresolved references to classes or interfaces. 
         You may need to specify additional library jars (using '-libraryjars'). 
Error: Please correct the above warnings first.
	at com.android.ide.eclipse.adt.internal.build.BuildHelper.runProguard(BuildHelper.java:590)
	at com.android.ide.eclipse.adt.internal.project.ExportHelper.exportReleaseApk(ExportHelper.java:265)
	... 4 more

3.找到问题

查看libs下面的jar包,比对proguard.cfg ,把没有添加的包,同样添加上Afinal的代码,打包时不混淆.

执行打包操作,结果仍然报错.


4.查看报错信息

Warning: com.android.util.CustomChartUtil: can't find referenced class org.achartengine.renderer.SimpleSeriesRenderer 
Warning: com.android.util.HttpClientHander: can't find referenced class org.apache.http.client.entity.GzipDecompressingEntity 
Warning: com.android.util.HttpClientHander: can't find referenced class org.apache.http.client.entity.GzipDecompressingEntity 
Warning: com.android.util.HttpClientTaskHander: can't find referenced class org.apache.http.client.entity.GzipDecompressingEntity 
Warning: com.android.util.HttpClientTaskHander: can't find referenced class org.apache.http.client.entity.GzipDecompressingEntity 


Warning: com.android.util.CustomChartUtil: can't find referenced class org.achartengine.renderer.XYMultipleSeriesRenderer 
Warning: com.android.util.CustomChartUtil: can't find referenced class org.achartengine.renderer.XYMultipleSeriesRenderer 
Warning: com.android.util.CustomChartUtil: can't find referenced class org.achartengine.renderer.XYMultipleSeriesRenderer 
Warning: com.android.util.CustomChartUtil: can't find referenced class org.achartengine.renderer.XYMultipleSeriesRenderer 
Warning: com.android.util.CustomChartUtil: can't find referenced class org.achartengine.renderer.XYMultipleSeriesRenderer 
Warning: com.android.util.CustomChartUtil: can't find referenced class org.achartengine.renderer.XYMultipleSeriesRenderer 

根据上面的信息,发现是找不到org.achartengine.renderer.** 文件和org.apache.http.** 文件,这样就简单了,查询可以知道,这两个类对应的是achartengine.jar和httpmime.jar.  拷贝这两个类,到项目中的libs下面.同样在proguard.cfg 中添加不混淆操作.


4.执行打包操作.

完美的打包出来了.反编译看一下,的的确确是被混淆了.


5.不解的地方


虽然是混淆成功,并打包成功了,但是,在项目中并没有用到achartengine.jar中的类文件.也算是遗留的问题了.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值