问题
I know, similar questions have been asked, but I think, my situation is different. Please don't delete.
I've started getting NoClassDefFoundError error after migrating to API 28, just like many other folks. I've seen others experienced this issue because Google has deprecated org.apache classes, which required changing manifest, but I don't use apache classes in my project.
What makes investigation difficult is that there is no custom classes in the stack trace below, and it's not even clear what class was not found. The worst part of it is that I can't reproduce the bug in an emulator, or on a real device, and could see it only in Google Play Store reports, which showed that all crashes have happened on Android 9 devices.
I've two questions about it:
- Does the fact that there is no custom classes in stack trace mean that that's an internal Google problem and I can't really fix it?
- How can I change my project to get more information, e.g. to see what class was not found?
On unrelated note, I think, maintaining newer Android's versions become very difficult and their support simply doesn't exist, so stackoverflow is my last hope.
java.lang.NoClassDefFoundError:
at com.google.android.a.a.m.d (m.java:266)
at com.google.android.a.a.m.a (m.java:113)
at com.google.android.a.a.g.a (g.java:206)
at com.google.android.a.a.g.a (g.java:166)
at com.google.android.a.a.e$a$2.run (e.java:242)
at android.os.Handler.handleCallback (Handler.java:873)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:214)
at android.os.HandlerThread.run (HandlerThread.java:65)
Caused by: java.lang.ClassNotFoundException:
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.google.android.a.a.m.d (m.java:266)
at com.google.android.a.a.m.a (m.java:113)
at com.google.android.a.a.g.a (g.java:206)
at com.google.android.a.a.g.a (g.java:166)
at com.google.android.a.a.e$a$2.run (e.java:242)
at android.os.Handler.handleCallback (Handler.java:873)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:214)
at android.os.HandlerThread.run (HandlerThread.java:65)
Below are also all dependencies that I use in this project:
dependencies {
implementation fileTree(include: ['*.aar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:mediarouter-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.android.gms:play-services-vision:15.0.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
implementation 'com.google.android.gms:play-services-drive:15.0.1'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.google.code.gson:gson:2.8.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.android.gms:play-services-wearable:15.0.1'
implementation 'com.google.android.gms:play-services-tasks:15.0.1'
implementation files('libs/accessory-v2.5.3.jar')
implementation files('libs/sdk-v1.0.0.jar')
implementation files('libs/lvl.aar')
}
It's a Kotlin project, and Kotlin version is 1.3.10
Update: Recompiled the same code with API 27, posted the app to Play Store again, and didn't see any crashes since then, so it's definitely specific to API 28.
回答1:
The mystery is solved. After all, it was related to org.apache classes and I'm sure, it will create a hidden problem for many folks migrating to API 28.
While my project doesn't have any dependency on Apache classes, Google own API (licensing library in my case) does have such a dependency.
So, even if you don't use Apache in your project directly, you never know what's in dependencies and that's why you should always have the below line in your manifest's application tag when deal with API 28:
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
Lastly, since Google Play Store did lousy job in providing a meaningful stack trace, I had to inject ACRA code to the app's beta code and to ask users to send a crash report to me. Fortunately, I had one user who has agreed to help with this. Below is what I've got through email.
My opinion about quality of Android platform gets worse with every new version they release.
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/client/utils/URLEncodedUtils;
at com.google.android.vending.licensing.ServerManagedPolicy.decodeExtras(ServerManagedPolicy.java:3)
at com.google.android.vending.licensing.ServerManagedPolicy.processServerResponse(ServerManagedPolicy.java:3)
at com.google.android.vending.licensing.LicenseValidator.handleResponse(LicenseValidator.java:1)
at com.google.android.vending.licensing.LicenseValidator.verify(LicenseValidator.java:37)
at com.google.android.vending.licensing.LicenseChecker$ResultListener$2.run(LicenseChecker.java:4)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.client.utils.URLEncodedUtils" on path: DexPathList[[zip file "/data/app/info.gryb.gacw-buYW6A5hesJP-wfcU6nnVg==/base.apk"],nativeLibraryDirectories=[/data/app/info.gryb.gacw-buYW6A5hesJP-wfcU6nnVg==/lib/arm64, /system/lib64, /system/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)
... 9 more
java.lang.ClassNotFoundException: Didn't find class "org.apache.http.client.utils.URLEncodedUtils" on path: DexPathList[[zip file "/data/app/info.gryb.gacw-buYW6A5hesJP-wfcU6nnVg==/base.apk"],nativeLibraryDirectories=[/data/app/info.gryb.gacw-buYW6A5hesJP-wfcU6nnVg==/lib/arm64, /system/lib64, /system/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.google.android.vending.licensing.ServerManagedPolicy.decodeExtras(ServerManagedPolicy.java:3)
at com.google.android.vending.licensing.ServerManagedPolicy.processServerResponse(ServerManagedPolicy.java:3)
at com.google.android.vending.licensing.LicenseValidator.handleResponse(LicenseValidator.java:1)
at com.google.android.vending.licensing.LicenseValidator.verify(LicenseValidator.java:37)
at com.google.android.vending.licensing.LicenseChecker$ResultListener$2.run(LicenseChecker.java:4)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.os.HandlerThread.run(HandlerThread.java:65)
来源:https://stackoverflow.com/questions/56330539/noclassdeffounderror-after-migrating-to-android-api-28