问题
I was working on my code. it was working fine on version 8(Oreo) after that I got an update of android v 9.0 (Pie) and the app stopped working suddenly. after checking I got a error message om my Asyn task stating the below error:
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.global.exch, PID: 25112
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:354)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/logging/LogFactory;
at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:182)
at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:150)
at com.global.exch.Dataholder.getApi(Dataholder.java:100)
at com.global.exch.MainActivity$QuotesData.doInBackground(MainActivity.java:391)
at com.global.exch.MainActivity$QuotesData.doInBackground(MainActivity.java:386)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.commons.logging.LogFactory" on path: DexPathList[[zip file "/data/app/com.global.exch-sEcnUuVsCYjXlnxJddVQAA==/base.apk", zip file "/data/app/com.global.exch-sEcnUuVsCYjXlnxJddVQAA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.global.exch-sEcnUuVsCYjXlnxJddVQAA==/split_lib_resources_apk.apk", zip file "/data/app/com.global.exch-sEcnUuVsCYjXlnxJddVQAA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.global.exch-sEcnUuVsCYjXlnxJddVQAA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.global.exch-sEcnUuVsCYjXlnxJddVQAA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.global.exch-sEcnUuVsCYjXlnxJddVQAA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.global.exch-sEcnUuVsCYjXlnxJddVQAA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.global.exch-sEcnUuVsCYjXlnxJddVQAA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.global.exch-sEcnUuVsCYjXlnxJddVQAA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.global.exch-sEcnUuVsCYjXlnxJddVQAA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.global.exch-sEcnUuVsCYjXlnxJddVQAA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.global.exch-sEcnUuVsCYjXlnxJddVQAA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.global.exch-sEcnUuVsCYjXlnxJddVQAA==/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 org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:182)
at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:150)
at com.global.exch.Dataholder.getApi(Dataholder.java:100)
at com.global.exch.MainActivity$QuotesData.doInBackground(MainActivity.java:391)
at com.global.exch.MainActivity$QuotesData.doInBackground(MainActivity.java:386)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.global.exch-sEcnUuVsCYjXlnxJddVQAA==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:354)
at dalvik.system.DexFile.<init>(DexFile.java:101)
at dalvik.system.DexFile.<init>(DexFile.java:75)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
E/AndroidRuntime: at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:718)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:801)
at android.app.LoadedApk.getResources(LoadedApk.java:1023)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5780)
at android.app.ActivityThread.access$1100(ActivityThread.java:200)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1660)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6762)
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)
Can anyone help me out what is the exact issue for this as it was working fine earlier. thank you in advance.
回答1:
I was also facing the same issue but After Adding the below code in my manifest file the issue got resolved
for reference you can also check this url: https://developer.android.com/about/versions/pie/android-9.0-changes-28
manifest.xml
<application
...
android:usesCleartextTraffic="true"
...>
<uses-library
android:name="org.apache.http.legacy"
android:required="false"/>
</application>
回答2:
How to update the existing project in androidx.
does not need to add the extra permission & code, dependencies,...
0.1): changes into the compileSdkVersion 29
0.2): Refactor-> Migrate to androidX then
Just add the following code in the project "ASDF":
1): add the XML directory,
1.1): Add the following code in XML, Code is below: i.e.
<application
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system"/>
</trust-anchors>
</base-config>
</network-security-config>
>
2): add the following code in the in manifest file:
2.1): within application tag the (manifest->application) add the following code:
android:networkSecurityConfig="@xml/network_security_config"
2.2): outside application tag the (manifest->application) add the following code:
<application>
<uses-library
android:name="org.apache.http.legacy"
android:required="false"/>
</application>
be happy and share your feedback with me Thank you**
来源:https://stackoverflow.com/questions/53995724/async-task-not-supporting-in-android-9-0-pie