![](/img/trans.png)
[英]NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/logging/LogFactory
[英]java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/logging/LogFactory
類似的問題已經需要問了。 但是由於 Android 平台兼容性的變化,這似乎比以前的更復雜。
這是我注冊了 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)
在運行 Android 7.0 及更低版本的設備上運行相同的代碼時,它運行良好。
我也嘗試向我的項目添加依賴項
implementation "commons-logging:commons-logging:1.2"
添加此依賴項可使應用程序在 Pixel 和 Pixel 中運行,但隨后在所有其他設備中崩潰,並顯示異常
org.apache.commons.logging.impl.LogFactoryImpl does not extend or implement org.apache.commons.logging.LogFactory
我已經嘗試在 ProGuard 中進行所有更改。 這是我的 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.*
仍然導致崩潰。
此問題與 Amazon AWS SDK 相關 - https://github.com/aws/aws-sdk-android/issues/476
在 AWS 更新其 SDK 以解決此問題之前,是否有任何解決方法?
在清單文件中添加以下行。
<uses-library android:name ="org.apache.http.legacy" android:required ="false"/>
這是一個 AWS SDK 錯誤,它似乎在 SDK 的 2.6.30 版中得到解決:
修復了使用 Apache Commons Logging 獲取記錄器會在啟動 Android 9.0(Pie / API Level 28)時崩潰的錯誤。 見拉#521。 現在,如果將 Apache Commons Logging 添加為依賴項,則將使用它,否則將使用 android.util.Log。
為了解決這個問題,我在 gradle 文件中有依賴實現“commons-logging:commons-logging-api:1.1” 。
另一種解決方法是將commons-logging
庫作為.jar
文件添加到您的libs/
文件夾中,而不是使用implementation
。 確保implementation fileTree(include: ['*.jar'], dir: 'libs')
在您的依賴項中。
commons-logging-1.2.jar
:
信用: 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.