在Eclipse打包工程时报如下错误:
[2016-04-01 16:36:10 - bjjwcjgc] Proguard returned with error code 1. See console
[2016-04-01 16:36:10 - bjjwcjgc] Note: there were 4 duplicate class definitions.[2016-04-01 16:36:10 - bjjwcjgc] (http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.PermissionCacheOptimizer: can't find superclass or interface org.springframework.aop.framework.AopInfrastructureBean[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.PermissionEvaluator: can't find superclass or interface org.springframework.aop.framework.AopInfrastructureBean[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.SecurityMetadataSource: can't find superclass or interface org.springframework.aop.framework.AopInfrastructureBean[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.event.AbstractAuthorizationEvent: can't find superclass or interface org.springframework.context.ApplicationEvent[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.event.LoggerListener: can't find superclass or interface org.springframework.context.ApplicationListener[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.expression.AbstractSecurityExpressionHandler: can't find superclass or interface org.springframework.context.ApplicationContextAware[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.expression.SecurityExpressionHandler: can't find superclass or interface org.springframework.aop.framework.AopInfrastructureBean[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.expression.method.MethodSecurityEvaluationContext: can't find superclass or interface org.springframework.expression.spel.support.StandardEvaluationContext[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.intercept.AbstractSecurityInterceptor: can't find superclass or interface org.springframework.beans.factory.InitializingBean[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.intercept.AbstractSecurityInterceptor: can't find superclass or interface org.springframework.context.ApplicationEventPublisherAware[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.intercept.AbstractSecurityInterceptor: can't find superclass or interface org.springframework.context.MessageSourceAware[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.intercept.AfterInvocationProviderManager: can't find superclass or interface org.springframework.beans.factory.InitializingBean[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.intercept.MethodInvocationPrivilegeEvaluator: can't find superclass or interface org.springframework.beans.factory.InitializingBean[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.intercept.RunAsImplAuthenticationProvider: can't find superclass or interface org.springframework.beans.factory.InitializingBean[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.intercept.RunAsImplAuthenticationProvider: can't find superclass or interface org.springframework.context.MessageSourceAware[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.intercept.RunAsManagerImpl: can't find superclass or interface org.springframework.beans.factory.InitializingBean[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor: can't find superclass or interface org.aopalliance.intercept.MethodInterceptor[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor: can't find superclass or interface org.springframework.aop.support.AbstractPointcutAdvisor[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor: can't find superclass or interface org.springframework.beans.factory.BeanFactoryAware[2016-04-01 16:36:10 - bjjwcjgc] Warning: org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor$MethodSecurityMetadataSourcePointcut: can't find superclass or interface org.springframework.aop.support.StaticMethodMatcherPointcut[2016-04-01 16:36:10 - bjjwcjgc] Warning: library class android.content.Intent depends on program class org.xmlpull.v1.XmlPullParser[2016-04-01 16:36:10 - bjjwcjgc] Warning: library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlSerializer[2016-04-01 16:36:10 - bjjwcjgc] Warning: library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlPullParser[2016-04-01 16:36:10 - bjjwcjgc] Warning: library class android.content.res.ColorStateList depends on program class org.xmlpull.v1.XmlPullParser[2016-04-01 16:36:10 - bjjwcjgc] Warning: library class android.graphics.drawable.ColorDrawable depends on program class org.xmlpull.v1.XmlPullParser[2016-04-01 16:36:10 - bjjwcjgc] Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser[2016-04-01 16:36:10 - bjjwcjgc] Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser[2016-04-01 16:36:10 - bjjwcjgc] Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser[2016-04-01 16:36:10 - bjjwcjgc] Warning: library class android.graphics.drawable.GradientDrawable depends on program class org.xmlpull.v1.XmlPullParser[2016-04-01 16:36:10 - bjjwcjgc] Warning: library class android.graphics.drawable.InsetDrawable depends on program class org.xmlpull.v1.XmlPullParser[2016-04-01 16:36:10 - bjjwcjgc] Warning: library class android.graphics.drawable.LayerDrawable depends on program class org.xmlpull.v1.XmlPullParser[2016-04-01 16:36:10 - bjjwcjgc] Warning: library class android.graphics.drawable.ShapeDrawable depends on program class org.xmlpull.v1.XmlPullParser[2016-04-01 16:36:10 - bjjwcjgc] Warning: library class android.graphics.drawable.ShapeDrawable depends on program class org.xmlpull.v1.XmlPullParser[2016-04-01 16:36:10 - bjjwcjgc] Warning: library class android.view.LayoutInflater depends on program class org.xmlpull.v1.XmlPullParser[2016-04-01 16:36:10 - bjjwcjgc] Warning: library class android.view.LayoutInflater depends on program class org.xmlpull.v1.XmlPullParser[2016-04-01 16:36:10 - bjjwcjgc] Warning: there were 910 unresolved references to classes or interfaces.[2016-04-01 16:36:10 - bjjwcjgc] You may need to add missing library jars or update their versions.[2016-04-01 16:36:10 - bjjwcjgc] If your code works fine without the missing classes, you can suppress[2016-04-01 16:36:10 - bjjwcjgc] the warnings with '-dontwarn' options.[2016-04-01 16:36:10 - bjjwcjgc] (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)[2016-04-01 16:36:10 - bjjwcjgc] Warning: there were 16 instances of library classes depending on program classes.[2016-04-01 16:36:10 - bjjwcjgc] You must avoid such dependencies, since the program classes will[2016-04-01 16:36:10 - bjjwcjgc] be processed, while the library classes will remain unchanged.[2016-04-01 16:36:10 - bjjwcjgc] (http://proguard.sourceforge.net/manual/troubleshooting.html#dependency)[2016-04-01 16:36:10 - bjjwcjgc] Warning: there were 12 unresolved references to program class members.[2016-04-01 16:36:10 - bjjwcjgc] Your input classes appear to be inconsistent.[2016-04-01 16:36:10 - bjjwcjgc] You may need to recompile the code.[2016-04-01 16:36:10 - bjjwcjgc] (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)[2016-04-01 16:36:10 - bjjwcjgc] java.io.IOException: Please correct the above warnings first.[2016-04-01 16:36:10 - bjjwcjgc] at proguard.Initializer.execute(Initializer.java:473)[2016-04-01 16:36:10 - bjjwcjgc] at proguard.ProGuard.initialize(ProGuard.java:222)[2016-04-01 16:36:10 - bjjwcjgc] at proguard.ProGuard.execute(ProGuard.java:97)[2016-04-01 16:36:10 - bjjwcjgc] at proguard.ProGuard.main(ProGuard.java:507)
大体意思是找不到相关的类或者方法,因为工程引入了第三方包,混淆的时候如果把第三方包也混淆了,那么相关的类在使用这些包的时候就会找不到相关方法。
因此在proguard-project.txt加上以下代码:
-dontwarn org.springframework.security.**-keep class org.springframework.security.** { *;}-dontwarn org.xmlpull.v1.**-keep class org.xmlpull.v1.** { *;}
其实找不到引用的这个类是第三方包里面的,而且很多时候我们只需要打乱自己的代码就行了,第三方包的代码就是否要打乱就不要管了。我们可以使用
-dontwarn com.xx.bbb.**-keep class com.xx.bbb.** { *;}
参数来保持第三方库中的类而不乱,-dontwarn和-keep 结合使用,意思是保持com.xx.bbb.**这个包里面的所有类和所有方法而不混淆,接着还叫ProGuard不要警告找不到com.xx.bbb.**这个包里面的类的相关引用。配置好后,重新打包,一切OK!而且程序能正确运行