AndroidStudio在Android9上调试闪退的问题

本文详细介绍了在Android9设备上安装APP时遇到的闪退问题及其解决方案,包括配置未知应用权限、添加Apache HTTP库支持及启用明文流量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天用我自己的手机安装我正在开发的APP的时候,出现闪退现象,我手机Android9的,在此记录下原因

代码逻辑有问题也可能导致闪退,我讲的不是代码逻辑的问题,而是配置的问题,你得先确定自己代码逻辑没问题再来看我说的。首先,Android8以上的手机需要配置以下权限,允许安装未知应用的权限,不然更新的自动安装的时候会安装不上。

<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>

然后Android9的手机安装闪退,并且报:

Android9.0_P:ClassNotFoundException:Didn't find class "org.apache.http.ProtocolVersion" on path:XXXXX

这么一个错。

需要在AndroidManifest.xml的application节点下 添加以下内容:

<uses-library
    android:name="org.apache.http.legacy"
    android:required="false" />
<application
            android:name=".application.MyApplication"
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:largeHeap="true"
            android:theme="@style/QMUI.Compat.NoActionBar"
            tools:ignore="GoogleAppIndexingWarning">
        <!--android9闪退-->
        <uses-library
                android:name="org.apache.http.legacy"
                android:required="false" />

加上这么一段代码之后呢,ClassNotFoundException的错是不报了,但是还是闪退,并给你一个

java.io.IOException: Cleartext HTTP traffic to xxx.xxx.xxx.xxx not permitted   

这样的错。据说是Android9.0 默认是禁止所有的http请求的,我们还需要在AndroidManifest.xml的application节点中加上android:usesCleartextTraffic="true"属性,如下:

<application
            android:name=".application.MyApplication"
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:largeHeap="true"
            android:theme="@style/QMUI.Compat.NoActionBar"
            android:usesCleartextTraffic="true"
            tools:ignore="GoogleAppIndexingWarning">
        <!--android9闪退-->
        <uses-library
                android:name="org.apache.http.legacy"
                android:required="false" />

这样Android9闪退的问题就解决啦!

分析以下代码的报错信息:------------------------- PROCESS STARTED (7432) for package com.example.myapplication ---------------------------- 2025-07-09 13:27:09.041 7432-7432 e.myapplicatio com.example.myapplication W ClassLoaderContext classpath size mismatch. expected=0, found=1 (PCL[] | PCL[/data/data/com.example.myapplication/code_cache/.overlay/base.apk/classes3.dex*4250602868]) 2025-07-09 13:27:09.042 7432-7432 e.myapplicatio com.example.myapplication W Found duplicate classes, falling back to extracting from APK : /data/app/~~dh0o8WK_fXecSV_JJz78RQ==/com.example.myapplication-RE5zX8NpQzXhviy1xPMobA==/base.apk 2025-07-09 13:27:09.042 7432-7432 e.myapplicatio com.example.myapplication W NOTE: This wastes RAM and hurts startup performance. 2025-07-09 13:27:09.042 7432-7432 e.myapplicatio com.example.myapplication W Found duplicated class when checking oat files: &#39;Lcom/example/myapplication/ListActivity$1;&#39; in /data/data/com.example.myapplication/code_cache/.overlay/base.apk/classes3.dex and /data/app/~~dh0o8WK_fXecSV_JJz78RQ==/com.example.myapplication-RE5zX8NpQzXhviy1xPMobA==/base.apk!classes3.dex 2025-07-09 13:27:09.172 7432-7432 NetworkSecurityConfig com.example.myapplication D No Network Security Config specified, using platform default 2025-07-09 13:27:09.173 7432-7432 NetworkSecurityConfig com.example.myapplication D No Network Security Config specified, using platform default 2025-07-09 13:27:09.201 7432-7456 libEGL com.example.myapplication D loaded /vendor/lib/egl/libEGL_emulation.so 2025-07-09 13:27:09.202 7432-7456 libEGL com.example.myapplication D loaded /vendor/lib/egl/libGLESv1_CM_emulation.so 2025-07-09 13:27:09.204 7432-7456 libEGL com.example.myapplication D loaded /vendor/lib/egl/libGLESv2_emulation.so 2025-07-09 13:27:09.246 7432-7432 AppCompatDelegate com.example.myapplication D Checking for metadata for AppLocalesMetadataHolderService : Service not found 2025-07-09 13:27:09.305 7432-7432 e.myapplicatio com.example.myapplication W Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) 2025-07-09 13:27:09.305 7432-7432 e.myapplicatio com.example.myapplication W Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) 2025-07-09 13:27:09.397 7432-7454 HostConnection com.example.myapplication D HostConnection::get() New Host Connection established 0xe9a68250, tid 7454 2025-07-09 13:27:09.403 7432-7454 HostConnection com.example.myapplication D HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data ANDROID_EMU_vulkan_async_qsri ANDROID_EMU_read_color_buffer_dma GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 2025-07-09 13:27:09.404 7432-7454 OpenGLRenderer com.example.myapplication W Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 2025-07-09 13:27:09.411 7432-7454 EGL_emulation com.example.myapplication D eglCreateContext: 0xe9a68170: maj 2 min 0 rcv 2 2025-07-09 13:27:09.414 7432-7454 EGL_emulation com.example.myapplication D eglMakeCurrent: 0xe9a68170: ver 2 0 (tinfo 0xe9db64d0) (first time) 2025-07-09 13:27:09.438 7432-7454 Gralloc4 com.example.myapplication I mapper 4.x is not supported 2025-07-09 13:27:09.439 7432-7454 HostConnection com.example.myapplication D createUnique: call 2025-07-09 13:27:09.439 7432-7454 HostConnection com.example.myapplication D HostConnection::get() New Host Connection established 0xe9a6acc0, tid 7454 2025-07-09 13:27:09.467 7432-7454 HostConnection com.example.myapplication D HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data ANDROID_EMU_vulkan_async_qsri ANDROID_EMU_read_color_buffer_dma GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 2025-07-09 13:27:10.478 7432-7432 AndroidRuntime com.example.myapplication D Shutting down VM 2025-07-09 13:27:10.479 7432-7432 AndroidRuntime com.example.myapplication E FATAL EXCEPTION: main Process: com.example.myapplication, PID: 7432 android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? at android.view.ViewRootImpl.setView(ViewRootImpl.java:1068) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:409) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:109) at android.app.Dialog.show(Dialog.java:340) at android.app.AlertDialog$Builder.show(AlertDialog.java:1131) at com.example.myapplication.MyBaseAdapter$1.onClick(MyBaseAdapter.java:55) at android.view.View.performClick(View.java:7448) at android.view.View.performClickInternal(View.java:7425) at android.view.View.access$3600(View.java:810) at android.view.View$PerformClick.run(View.java:28305) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 2025-07-09 13:27:10.509 7432-7432 Process com.example.myapplication I Sending signal. PID: 7432 SIG: 9 ---------------------------- PROCESS ENDED (7432) for package com.example.myapplication ----------------------------
07-10
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值