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?
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.
Add this below line in menifest file.
<uses-library android:name ="org.apache.http.legacy" android:required ="false"/>
to fix this issue I had the dependency implementation "commons-logging:commons-logging-api:1.1" in gradle file.
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
:
Credit: Dale Lim - https://github.com/aws/aws-sdk-android/issues/265#issuecomment-411978696
来源:https://stackoverflow.com/questions/51872333/java-lang-noclassdeffounderror-failed-resolution-of-lorg-apache-commons-loggin