如何修复我的android应用无法在android 9上运行?

时间:2019-12-20 14:33:14

标签: android android-asynctask android-9.0-pie

我的android应用在9以下的android上工作正常,但在android 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) 

1 个答案:

答案 0 :(得分:0)

问题是因为android 9及更高版本使用SSL套接字(HTTPS Ports)进行通信,在这种情况下使用的是http端口。通过将以下行添加到清单文件中解决了问题

 android:usesCleartextTraffic="true">
    <uses-library android:name="org.apache.http.legacy" android:required="false" />