显示天气信息的应用程序在模拟器上运行,而不是在实际手机上运行

问题描述

    /15 18:04:40: Launching 'app' on Xiaomi Redmi 6 Pro.
Install successfully finished in 7 s 219 ms.
$ adb shell am start -n "com.example.weatherapp/com.example.weatherapp.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 31272 on device 'xiaomi-redmi_6_pro-1f01c0720405'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/Perf: Connecting to perf service.
I/MultiDex: VM with version 2.1.0 has multidex support
    Installing application
    VM has multidex support,MultiDex support library is disabled.
W/mple.weatherap: Accessing hidden method Landroid/graphics/drawable/Drawable;->getopticalInsets()Landroid/graphics/Insets; (light greylist,linking)
    Accessing hidden field Landroid/graphics/Insets;->left:I (light greylist,linking)
W/mple.weatherap: Accessing hidden field Landroid/graphics/Insets;->right:I (light greylist,linking)
    Accessing hidden field Landroid/graphics/Insets;->top:I (light greylist,linking)
    Accessing hidden field Landroid/graphics/Insets;->bottom:I (light greylist,linking)
W/mple.weatherap: Accessing hidden field Landroid/view/WindowInsets;->CONSUMED:Landroid/view/WindowInsets; (light greylist,reflection)
W/mple.weatherap: Accessing hidden method Landroid/view/View;->getAccessibilityDelegate()Landroid/view/View$AccessibilityDelegate; (light greylist,linking)
W/mple.weatherap: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist,reflection)
W/mple.weatherap: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist,reflection)
W/Looper: Slow Looper: Activity com.example.weatherapp/.MainActivity is 488ms late (wall=767ms running=0ms ClientTransaction{ callbacks=[android.app.servertransaction.LaunchActivityItem] lifecycleRequest=android.app.servertransaction.ResumeActivityItem }) because of 2 msg,msg 1 took 528ms (late=4ms h=android.app.ActivityThread$H w=110)
W/mple.weatherap: Accessing hidden method Landroid/graphics/Insets;->of(IIII)Landroid/graphics/Insets; (light greylist,linking)
I/Adreno: QUALCOMM build                   : 2df12b3,I07da2d9908
    Build Date                       : 10/04/18
    OpenGL ES Shader Compiler Version: EV031.25.03.01
    Local Branch                     : 
    Remote Branch                    : 
    Remote Branch                    : 
    Reconstruct Branch               : 
    Build Config                     : S L 6.0.7 AArch64
I/Adreno: PFP: 0x005ff110,ME: 0x005ff066
I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColordisplay retrieved: 0
    android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRdisplay retrieved: 0
I/Openglrenderer: Initialized EGL,version 1.4
D/Openglrenderer: Swap behavior 2
I/AssistStructure: Flattened final assist data: 5204 bytes,containing 1 windows,20 views
I/DpmTcmClient: RegisterTcmMonitor from: com.android.okhttp.TcmIdleTimerMonitor
D/NetworkSecurityConfig: No Network Security Config specified,using platform default
W/System.err: java.io.IOException: Cleartext HTTP traffic to api.openweathermap.org not permitted
W/System.err:     at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:115)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:458)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:407)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:244)
        at com.example.weatherapp.MainActivity$DownloadJSON.doInBackground(MainActivity.java:60)
        at com.example.weatherapp.MainActivity$DownloadJSON.doInBackground(MainActivity.java:41)
        at android.os.AsyncTask$2.call(AsyncTask.java:333)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/System.err:     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)
W/System.err: org.json.JSONException: End of input at character 0 of 
        at org.json.JSONTokener.SyntaxError(JSONTokener.java:449)
W/System.err:     at org.json.JSONTokener.nextValue(JSONTokener.java:97)
        at org.json.JSONObject.<init>(JSONObject.java:159)
        at org.json.JSONObject.<init>(JSONObject.java:176)
        at com.example.weatherapp.MainActivity.Getinformation(MainActivity.java:141)
        at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409)
        at android.view.View.performClick(View.java:6616)
        at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
        at android.view.View.performClickInternal(View.java:6593)
        at android.view.View.access$3100(View.java:785)
        at android.view.View$PerformClick.run(View.java:25929)
W/System.err:     at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:201)
        at android.app.ActivityThread.main(ActivityThread.java:6806)
        at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

这是运行时块 我已经尝试过 android:text 建议的并且还在 gradle(app) 文件中启用 multiDexEnabled true 坚果对我不起作用 谁能帮我吗?.. **这是一个简单的应用程序,它只显示来自 api 密钥的天气信息,它适用于模拟器,但不适用于手机 **

块引用

解决方法

错误似乎是:Cleartext HTTP traffic to api.openweathermap.org not permitted

明文是指传输的任何未加密的信息,这意味着您要么尝试通过 http url 而不是 https 联系 API,或者您所在设备的 API运行代码高于Android 9,禁用明文通信。

查看官方 Android documentation for this 以及此 question 以获取更多信息。