Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 472
Mohammed Atif Avatar asked Aug 16 '18 08:08

Mohammed Atif


2 Answers

Add this below line in manifest file.

<uses-library android:name ="org.apache.http.legacy" android:required ="false"/> 
like image 174
Rajan Kashiyani Avatar answered Oct 06 '22 07:10

Rajan Kashiyani


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.

like image 23
Roy Solberg Avatar answered Oct 06 '22 08:10

Roy Solberg