简体   繁体   中英

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.

Here is my error log from Pixel and Pixel2 which are signed up for Android Beta Program

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.

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

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. Here is my proguard configuration

-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

Is there any workaround till AWS updates their SDK to fix this issue?

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

<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 :

Fixed a bug where getting a logger using Apache Commons Logging would crash starting Android 9.0 (Pie / API Level 28). See pull #521. Now, Apache Commons Logging would be used if it's being added as a dependency, otherwise android.util.Log will be used.

为了解决这个问题,我在 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 . Make sure that implementation fileTree(include: ['*.jar'], dir: 'libs') is in your dependencies.

Sources of commons-logging-1.2.jar :

  1. Maven Repository
  2. Apache Commons Logging

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM