简体   繁体   English

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

[英]java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/logging/LogFactory

Similar questions have need asked already.类似的问题已经需要问了。 But this one seems to be more complicated than previous ones because of changes in compatibility of Android Platforms.但是由于 Android 平台兼容性的变化,这似乎比以前的更复杂。

Here is my error log from Pixel and Pixel2 which are signed up for Android Beta Program这是我注册了 Android Beta 程序的 Pixel 和 Pixel2 的错误日志

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) 

Same code when ran on Devices running Android 7.0 and below, it works perfectly fine.在运行 Android 7.0 及更低版本的设备上运行相同的代码时,它运行良好。

I tried adding dependency to my project too我也尝试向我的项目添加依赖项

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

Adding this dependency makes the app work in Pixel and Pixel but then it crashes in all other devices with Exception saying添加此依赖项可使应用程序在 Pixel 和 Pixel 中运行,但随后在所有其他设备中崩溃,并显示异常

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

I tried doing all the changes in ProGuard already.我已经尝试在 ProGuard 中进行所有更改。 Here is my proguard configuration这是我的 proguard 配置

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

Still causing the crash.仍然导致崩溃。

This issue is related to Amazon AWS SDK - https://github.com/aws/aws-sdk-android/issues/476此问题与 Amazon AWS SDK 相关 - https://github.com/aws/aws-sdk-android/issues/476

Is there any workaround till AWS updates their SDK to fix this issue?在 AWS 更新其 SDK 以解决此问题之前,是否有任何解决方法?

在清单文件中添加以下行。

<uses-library android:name ="org.apache.http.legacy" android:required ="false"/>

This is an AWS SDK bug that appears to be solved in version 2.6.30 of the SDK :这是一个 AWS SDK 错误,它似乎在 SDK 的 2.6.30 版中得到解决:

Fixed a bug where getting a logger using Apache Commons Logging would crash starting Android 9.0 (Pie / API Level 28).修复了使用 Apache Commons Logging 获取记录器会在启动 Android 9.0(Pie / API Level 28)时崩溃的错误。 See pull #521.见拉#521。 Now, Apache Commons Logging would be used if it's being added as a dependency, otherwise android.util.Log will be used.现在,如果将 Apache Commons Logging 添加为依赖项,则将使用它,否则将使用 android.util.Log。

为了解决这个问题,我在 gradle 文件中有依赖实现“commons-logging:commons-logging-api:1.1”

An alternative workaround is to add the commons-logging library as a .jar file to your libs/ folder instead of using implementation .另一种解决方法是将commons-logging库作为.jar文件添加到您的libs/文件夹中,而不是使用implementation Make sure that implementation fileTree(include: ['*.jar'], dir: 'libs') is in your dependencies.确保implementation fileTree(include: ['*.jar'], dir: 'libs')在您的依赖项中。

Sources of commons-logging-1.2.jar : commons-logging-1.2.jar

  1. Maven Repository Maven 存储库
  2. Apache Commons Logging Apache 公共日志记录

Credit: Dale Lim - https://github.com/aws/aws-sdk-android/issues/265#issuecomment-411978696信用: Dale Lim - https://github.com/aws/aws-sdk-android/issues/265#issuecomment-411978696

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NoClassDefFoundError:解析失败:Lorg/apache/commons/logging/LogFactory - NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/logging/LogFactory java.lang.NoClassDefFoundError:解析失败:Lorg/apache/http/ProtocolVersion - java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion org.apache.http.conn.ssl上的java.lang.NoClassDefFoundError org / apache / commons / logging / LogFactory - java.lang.NoClassDefFoundError org/apache/commons/logging/LogFactory at org.apache.http.conn.ssl 错误:java.lang.NoClassDefFoundError:无法解决以下问题:Lorg / apache / xmlbeans / XmlOptions; - error: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/xmlbeans/XmlOptions; Android致命异常:java.lang.NoClassDefFoundError:解析失败:Lorg / apache / http / RequestLine; - Android Fatal Exception: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/RequestLine; Java.lang.NoClassDefFoundError:无法解决以下问题:Lorg / apache / http / entity / ContentType; - Java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/entity/ContentType; java.lang.NoClassDefFoundError:无法解决以下问题:Lorg / apache / http / params / BasicHttpParams; - java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/params/BasicHttpParams; Android 谷歌地图 java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion - Android Google maps java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion java.lang.NoClassDefFoundError:解析失败:Lorg / junit / runner / notification / RunListener - java.lang.NoClassDefFoundError: Failed resolution of: Lorg/junit/runner/notification/RunListener Android - java.lang.NoClassDefFoundError:解析失败:Lorg/slf4j/LoggerFactory; - Android - java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM