java.lang.NoSuchMethodError:org.apache.commons.logging.LogFactory

时间:2011-06-25 08:57:42

标签: java apache-commons-logging

当我为android启用proguard时,proguard会混淆应用程序中包含的所有jar。这些罐子包括:

  • libraryjars lib / Analytics_Android_SDK_2.1.jar
  • libraryjars lib / commons-codec.jar
  • libraryjars lib / commons-httpclient-3.1.jar
  • libraryjars lib / commons-logging-1.1.jar
  • libraryjars lib / weibo.jar
  • libraryjars lib / signpost-core-1.2.1.1.jar
  • libraryjars lib / signpost-commonshttp4-1.2.1.1.jar
  • libraryjars lib / youmibannerad-android.jar

在构建已签名的jar时,我得到以下转储:

    06-25 16:07:25.094: WARN/dalvikvm(13785): Exception Ljava/lang/NoSuchMethodError; own   while initializing Lorg/apache/commons/httpclient/HttpMethodBase;
    06-25 16:07:25.094: WARN/dalvikvm(13785): threadid=14: thread exiting with uncaught exception (group=0x40015560)
    06-25 16:07:25.104: ERROR/AndroidRuntime(13785): FATAL EXCEPTION: Thread-18
     06-25 16:07:25.104: ERROR/AndroidRuntime(13785): java.lang.ExceptionInInitializerError
     06-25 16:07:25.104: ERROR/AndroidRuntime(13785):     at weibo4andriod.http.HttpClient.a(Unknown Source)
     06-25 16:07:25.104: ERROR/AndroidRuntime(13785):     at weibo4andriod.Weibo.a(Unknown  
    Source)
     06-25 16:07:25.104: ERROR/AndroidRuntime(13785):     at com.snda.childbook.UpdateStatusThread.run(Unknown Source)
     06-25 16:07:25.104: ERROR/AndroidRuntime(13785):     at java.lang.Thread.run(Thread.java:1019)
     06-25 16:07:25.104: ERROR/AndroidRuntime(13785): Caused by: java.lang.NoSuchMethodError: org.apache.commons.logging.LogFactory.c
     06-25 16:07:25.104: ERROR/AndroidRuntime(13785):     at org.apache.commons.httpclient.HttpMethodBase.<clinit>(Unknown Source)
     06-25 16:07:25.104: ERROR/AndroidRuntime(13785):     ... 4 more
     06-25 16:07:25.104: WARN/ActivityManager(104):   Force finishing activity com.snda.childbook/.BookReader 

实际上这个项目是关于新浪微博的SDK,当我使用proguard对其进行模糊处理时,我总是失败,错误如下:

testpostmethord] Proguard returned with error code 1. See console
[2011-06-27 15:31:11 - testpostmethord] Note: there were 1 duplicate class definitions.
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.ServletContextCleaner: can't find superclass or interface javax.servlet.ServletContextListener
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.apache.avalon.framework.logger.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Category
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Category
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Priority
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Priority
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Priority
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Priority
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Priority
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Category
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Category
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Category
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Priority
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Category
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Priority
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Hierarchy
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Hierarchy
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Hierarchy
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.apache.log.Logger
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.ServletContextCleaner: can't find referenced class javax.servlet.ServletContextListener
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.ServletContextCleaner: can't find referenced class javax.servlet.ServletContextEvent
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.ServletContextCleaner: can't find referenced class javax.servlet.ServletContextEvent
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.ServletContextCleaner: can't find referenced class javax.servlet.ServletContextEvent
[2011-06-27 15:31:11 - testpostmethord] Warning: org.apache.commons.logging.impl.ServletContextCleaner: can't find referenced class javax.servlet.ServletContextEvent
[2011-06-27 15:31:11 - testpostmethord]       You should check if you need to specify additional program jars.
[2011-06-27 15:31:11 - testpostmethord] Warning: there were 70 unresolved references to classes or interfaces.
[2011-06-27 15:31:11 - testpostmethord]          You may need to specify additional library jars (using '-libraryjars').
[2011-06-27 15:31:11 - testpostmethord] java.io.IOException: Please correct the above warnings first.
[2011-06-27 15:31:11 - testpostmethord]     at proguard.Initializer.execute(Initializer.java:321)
[2011-06-27 15:31:11 - testpostmethord]     at proguard.ProGuard.initialize(ProGuard.java:211)
[2011-06-27 15:31:11 - testpostmethord]     at proguard.ProGuard.execute(ProGuard.java:86)
[2011-06-27 15:31:11 - testpostmethord]     at proguard.ProGuard.main(ProGuard.java:492)

所以我将代码-ignorewarnings添加到proguard配置文件中,所以警告全部被驳回,但是当我运行应用程序时,标题中的错误将会发生。

2 个答案:

答案 0 :(得分:4)

在外包项目中遇到同样的问题,似乎开发人员已经使用了世界上所有可能的免费图书馆。

最安全的方法是为ProGuard提供原始库作为参考,即使其中一些已被弃用且可能永远不会被您的代码调用:

Log4J - http://logging.apache.org/log4j/1.2/download.html

阿瓦隆 - http://www.docjar.com/jar_detail/avalon-framework-4.2.0.jar.html

Avalon LogKit - http://www.jarfinder.com/index.php/jars/versionInfo/17610

J2EE参考 - http://www.jarfinder.com/index.php/jars/versionInfo/4598

下载完所有的罐子后,请将ProGuard指向他们:

# Apache commomns-logging fun

-libraryjars proguard_ref_lib/log4j-1.2.17.jar
-libraryjars proguard_ref_lib/avalon-framework-4.2.0.jar
-libraryjars proguard_ref_lib/avalon-logkit-2.2.1.jar
-libraryjars proguard_ref_lib/servlet-api-6.0.16.jar

# Apache commomns-logging fun ends

享受

答案 1 :(得分:1)

我会尝试commons-logging-1.1.1。似乎版本不匹配