Android基础应用出现Invalid ID 0x00000000错误求助
Android 11(API 30)模拟器中“Invalid ID 0x00000000”错误原因分析
通过Android Studio向导创建基础Activity应用,在Android 11(API 30)模拟器运行时,Logcat出现错误提示:E Invalid ID 0x00000000.
日志信息
2024-03-05 18:05:59.402 13511-13511 NetworkSecurityConfig com.tst.test_service D No Network Security Config specified, using platform default 2024-03-05 18:05:59.477 13511-13527 System com.tst.test_service W A resource failed to call close. 2024-03-05 18:05:59.485 13511-13537 libEGL com.tst.test_service D loaded /vendor/lib/egl/libEGL_emulation.so 2024-03-05 18:05:59.488 13511-13537 libEGL com.tst.test_service D loaded /vendor/lib/egl/libGLESv1_CM_emulation.so 2024-03-05 18:05:59.491 13511-13537 libEGL com.tst.test_service D loaded /vendor/lib/egl/libGLESv2_emulation.so 2024-03-05 18:05:59.593 13511-13511 AppCompatDelegate com.tst.test_service D Checking for metadata for AppLocalesMetadataHolderService : Service not found 2024-03-05 18:05:59.678 13511-13511 st.test_servic com.tst.test_service E Invalid ID 0x00000000. 2024-03-05 18:05:59.748 13511-13511 st.test_servic com.tst.test_service W Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) 2024-03-05 18:05:59.748 13511-13511 st.test_servic com.tst.test_service W Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) 2024-03-05 18:05:59.954 13511-13511 Choreographer com.tst.test_service I Skipped 31 frames! The application may be doing too much work on its main thread. 2024-03-05 18:06:00.014 13511-13535 HostConnection com.tst.test_service D HostConnection::get() New Host Connection established 0xeb1e0760, tid 13535 2024-03-05 18:06:00.018 13511-13535 HostConnection com.tst.test_service 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 2024-03-05 18:06:00.019 13511-13535 OpenGLRenderer com.tst.test_service W Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 2024-03-05 18:06:00.031 13511-13535 EGL_emulation com.tst.test_service D eglCreateContext: 0xeb1e12c0: maj 2 min 0 rcv 2 2024-03-05 18:06:00.088 13511-13535 EGL_emulation com.tst.test_service D eglMakeCurrent: 0xeb1e12c0: ver 2 0 (tinfo 0xbc976ab0) (first time) 2024-03-05 18:06:00.104 13511-13535 Gralloc4 com.tst.test_service I mapper 4.x is not supported 2024-03-05 18:06:00.105 13511-13535 HostConnection com.tst.test_service D createUnique: call 2024-03-05 18:06:00.105 13511-13535 HostConnection com.tst.test_service D HostConnection::get() New Host Connection established 0xeb1e2670, tid 13535 2024-03-05 18:06:00.106 13511-13535 goldfish-address-space com.tst.test_service D allocate: Ask for block of size 0x100 2024-03-05 18:06:00.107 13511-13535 goldfish-address-space com.tst.test_service D allocate: ioctl allocate returned offset 0x3f3ffe000 size 0x2000 2024-03-05 18:06:00.110 13511-13535 HostConnection com.tst.test_service 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 2024-03-05 18:06:00.148 13511-13535 OpenGLRenderer com.tst.test_service I Davey! duration=707ms; Flags=1, IntendedVsync=3550308496207, Vsync=3550825162853, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=3550839799700, AnimationStart=3550839851400, PerformTraversalsStart=3550840685700, DrawStart=3550998421400, SyncQueued=3551001820600, SyncStart=3551019359600, IssueDrawCommandsStart=3551019448800, SwapBuffers=3551032163600, FrameCompleted=3551033766800, DequeueBufferDuration=285500, QueueBufferDuration=455600, GpuCompleted=72904454231491230, 2024-03-05 18:06:05.262 13511-13540 ProfileInstaller com.tst.test_service D Installing profile for com.tst.test_service
应用代码
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EdgeToEdge.enable(this); setContentView(R.layout.activity_main); ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); return insets; }); } }
布局文件activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout>
错误原因分析
这个错误的核心原因是**EdgeToEdge.enable(this)方法在Android 11(API 30)上存在兼容性问题**。
EdgeToEdge是AndroidX Core库提供的边缘到边缘布局工具,它内部会尝试配置系统状态栏、导航栏的透明度和颜色以实现沉浸式效果。但在API 30及以下版本中,该方法会尝试访问一个仅在API 31(Android 12)及以上系统中存在的资源ID,导致资源查找失败,返回无效ID 0x00000000,进而触发日志中的错误。
日志后续出现的隐藏方法调用警告,也是EdgeToEdge在低版本系统上通过反射调用未公开API导致的,属于同一类兼容性问题。
解决办法
- 方法一:将
EdgeToEdge.enable(this)的调用限制在API 31及以上版本:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { EdgeToEdge.enable(this); }
- 方法二:替换为低版本兼容的边缘到边缘实现,直接调用系统API:
getWindow().setDecorFitsSystemWindows(false);
内容的提问来源于stack exchange,提问作者vico
相关产品推荐
相关产品推荐

