我的安卓应用程序在低于 9 的安卓上运行良好,但在安卓 9 上不起作用,应用程序将在手机上运行后关闭Myappname Keeps Stop
并出现错误。
我已经用SDKVersion和TargetSDKversion 28(Android 9(构建了应用程序。请帮助我如何将我的应用程序与 android 9 兼容
这是我的应用程序崩溃时的Logcat,我认为后台进程有问题
--------- beginning of crash
2019-12-20 18:08:33.181 9444-9499/com.example.asanbekhar E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
Process: com.example.asanbekhar, PID: 9444
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: Ljavax/xml/bind/DatatypeConverter;
at org.scribe.services.DatatypeConverterEncoder.encode(DatatypeConverterEncoder.java:10)
at org.scribe.services.HMACSha1SignatureService.bytesToBase64String(HMACSha1SignatureService.java:51)
at org.scribe.services.HMACSha1SignatureService.doSign(HMACSha1SignatureService.java:46)
at org.scribe.services.HMACSha1SignatureService.getSignature(HMACSha1SignatureService.java:32)
at org.scribe.oauth.OAuth10aServiceImpl.getSignature(OAuth10aServiceImpl.java:151)
at org.scribe.oauth.OAuth10aServiceImpl.addOAuthParams(OAuth10aServiceImpl.java:75)
at org.scribe.oauth.OAuth10aServiceImpl.signRequest(OAuth10aServiceImpl.java:126)
at com.ciyashop.library.apicall.PostApi$postAPiCall.doInBackground(PostApi.java:109)
at com.ciyashop.library.apicall.PostApi$postAPiCall.doInBackground(PostApi.java:40)
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 "javax.xml.bind.DatatypeConverter" on path: DexPathList[[zip file "/data/app/com.example.asanbekhar-YRxDnKrurpdOW4cXsei4lA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.asanbekhar-YRxDnKrurpdOW4cXsei4lA==/lib/x86, /system/lib]]
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.scribe.services.DatatypeConverterEncoder.encode(DatatypeConverterEncoder.java:10)
at org.scribe.services.HMACSha1SignatureService.bytesToBase64String(HMACSha1SignatureService.java:51)
at org.scribe.services.HMACSha1SignatureService.doSign(HMACSha1SignatureService.java:46)
at org.scribe.services.HMACSha1SignatureService.getSignature(HMACSha1SignatureService.java:32)
at org.scribe.oauth.OAuth10aServiceImpl.getSignature(OAuth10aServiceImpl.java:151)
at org.scribe.oauth.OAuth10aServiceImpl.addOAuthParams(OAuth10aServiceImpl.java:75)
at org.scribe.oauth.OAuth10aServiceImpl.signRequest(OAuth10aServiceImpl.java:126)
at com.ciyashop.library.apicall.PostApi$postAPiCall.doInBackground(PostApi.java:109)
at com.ciyashop.library.apicall.PostApi$postAPiCall.doInBackground(PostApi.java:40)
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)
2019-12-20 18:08:33.192 9444-9499/com.example.asanbekhar E/UncaughtException: 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: Ljavax/xml/bind/DatatypeConverter;
at org.scribe.services.DatatypeConverterEncoder.encode(DatatypeConverterEncoder.java:10)
at org.scribe.services.HMACSha1SignatureService.bytesToBase64String(HMACSha1SignatureService.java:51)
at org.scribe.services.HMACSha1SignatureService.doSign(HMACSha1SignatureService.java:46)
at org.scribe.services.HMACSha1SignatureService.getSignature(HMACSha1SignatureService.java:32)
at org.scribe.oauth.OAuth10aServiceImpl.getSignature(OAuth10aServiceImpl.java:151)
at org.scribe.oauth.OAuth10aServiceImpl.addOAuthParams(OAuth10aServiceImpl.java:75)
at org.scribe.oauth.OAuth10aServiceImpl.signRequest(OAuth10aServiceImpl.java:126)
at com.ciyashop.library.apicall.PostApi$postAPiCall.doInBackground(PostApi.java:109)
at com.ciyashop.library.apicall.PostApi$postAPiCall.doInBackground(PostApi.java:40)
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 "javax.xml.bind.DatatypeConverter" on path: DexPathList[[zip file "/data/app/com.example.asanbekhar-YRxDnKrurpdOW4cXsei4lA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.asanbekhar-YRxDnKrurpdOW4cXsei4lA==/lib/x86, /system/lib]]
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.scribe.services.DatatypeConverterEncoder.encode(DatatypeConverterEncoder.java:10)
at org.scribe.services.HMACSha1SignatureService.bytesToBase64String(HMACSha1SignatureService.java:51)
at org.scribe.services.HMACSha1SignatureService.doSign(HMACSha1SignatureService.java:46)
at org.scribe.services.HMACSha1SignatureService.getSignature(HMACSha1SignatureService.java:32)
at org.scribe.oauth.OAuth10aServiceImpl.getSignature(OAuth10aServiceImpl.java:151)
at org.scribe.oauth.OAuth10aServiceImpl.addOAuthParams(OAuth10aServiceImpl.java:75)
at org.scribe.oauth.OAuth10aServiceImpl.signRequest(OAuth10aServiceImpl.java:126)
at com.ciyashop.library.apicall.PostApi$postAPiCall.doInBackground(PostApi.java:109)
at com.ciyashop.library.apicall.PostApi$postAPiCall.doInBackground(PostApi.java:40)
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)
问题是因为 android 9 及更高版本使用 SSL 套接字( HTTPS 端口 ( 进行通信,在这种情况下使用的是 http 端口。将下面这一行添加到清单文件解决了问题
android:usesCleartextTraffic="true">
<uses-library android:name="org.apache.http.legacy" android:required="false" />