代码之家  ›  专栏  ›  技术社区  ›  Mohammed Atif

java.lang.NoClassDefFoundError:解析失败:Lorg/apache/commons/logging/LogFactory

  •  10
  • Mohammed Atif  · 技术社区  · 6 年前

    类似的问题已经提出了。但由于Android平台兼容性的变化,这一次似乎比之前的更为复杂。

    08-16 13:20:53.146 9630-9630/? E/AndroidRuntime: FATAL EXCEPTION: main
        Process: me.project.android.dev, PID: 9630
        java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/logging/LogFactory;
            at com.amazonaws.util.VersionInfoUtils.<clinit>(VersionInfoUtils.java:41)
            at com.amazonaws.util.VersionInfoUtils.c(VersionInfoUtils.java:77)
            at com.amazonaws.ClientConfiguration.<clinit>(ClientConfiguration.java:43)
            //project specific class reference removed
            at android.os.Handler.handleCallback(Handler.java:873)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:6669)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
         Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.commons.logging.LogFactory" on path: DexPathList[[zip file "/data/app/me.project.android.dev-0SPRJnc8-4voauRU7Y20zQ==/base.apk"],nativeLibraryDirectories=[/data/app/me.project.android.dev-0SPRJnc8-4voauRU7Y20zQ==/lib/arm64, /data/app/me.project.android.dev-0SPRJnc8-4voauRU7Y20zQ==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
            at com.amazonaws.util.VersionInfoUtils.<clinit>(VersionInfoUtils.java:41) 
            at com.amazonaws.util.VersionInfoUtils.c(VersionInfoUtils.java:77) 
            at com.amazonaws.ClientConfiguration.<clinit>(ClientConfiguration.java:43) 
            //project specific class reference removed
            at android.os.Handler.handleCallback(Handler.java:873) 
            at android.os.Handler.dispatchMessage(Handler.java:99) 
            at android.os.Looper.loop(Looper.java:193) 
            at android.app.ActivityThread.main(ActivityThread.java:6669) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
    

    同样的代码在运行Android 7.0和更低版本的设备上运行时,它运行得非常好。

    我也试着在我的项目中添加依赖项

    implementation "commons-logging:commons-logging:1.2"
    

    添加此依赖项使应用程序在像素和像素中工作,但随后它在所有其他设备中崩溃,除了说

    org.apache.commons.logging.impl.LogFactoryImpl does not extend or implement org.apache.commons.logging.LogFactory
    

    -keep class org.apache.commons.logging.impl.LogFactoryImpl
    -keep class org.apache.commons.logging.LogFactory
    -keepnames class org.apache.commons.logging.impl.* {*;}
    -keepnames class org.apache.commons.logging.*
    -keepclassmembers class org.apache.commons.logging.impl.* {*;}
    -keepclassmembers class org.apache.commons.logging.*
    -keepnames interface org.apache.commons.logging.impl.* {*;}
    -keepnames interface org.apache.commons.logging.*
    

    仍在导致坠机。

    此问题与Amazon AWS SDK有关- https://github.com/aws/aws-sdk-android/issues/476

    在AWS更新SDK来解决这个问题之前,有什么解决方法吗?

    3 回复  |  直到 6 年前
        1
  •  26
  •   Roy Solberg    6 年前

    这是一个AWS SDK错误,似乎在 version 2.6.30 of the SDK

    修复了使用Apache Commons日志获取记录器将 启动Android 9.0(Pie/API级别28)时崩溃。参见拉动521。现在, 如果将Apache Commons日志添加为 依赖项,否则将使用android.util.Log。

        2
  •  34
  •   Makalele    5 年前

    将此添加到清单文件的下面一行。

    <uses-library android:name ="org.apache.http.legacy" android:required ="false"/>
    
        3
  •  8
  •   Malcom    5 年前

    为了解决这个问题我有依赖性 实现“commons logging:commons logging api:1.1” 在梯度文件中。

        4
  •  1
  •   m00head    6 年前

    另一种解决方法是添加 commons-logging 图书馆作为 .jar libs/ 文件夹而不是使用 implementation . 确保 implementation fileTree(include: ['*.jar'], dir: 'libs') 在你的依赖中。

    commons-logging-1.2.jar :

    1. Maven Repository
    2. Apache Commons Logging

    戴尔林- https://github.com/aws/aws-sdk-android/issues/265#issuecomment-411978696

        5
  •  0
  •   Ashif    5 年前
       /*Apache Commons Logging would crash starting Android 9.0 (Pie / API Level 28).*/
    
       //try this 
    
        testImplementation 'commons-logging:commons-logging:1.2'
    
        // in manifest  <application> s
        <uses-library android:name="org.apache.http.legacy" android:required="false" />
    
         /* if this files  'commons-logging:commons-logging:1.2' fails to download  then
          download this file manual  from http://commons.apache.org/proper/commons- 
           logging/download_logging.cgi and paste it lib folder*/