You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Navigation Drawer布局预览不显示,Android Studio卡在“等待构建完成”

解决Navigation Drawer XML编辑时“Waiting for build to finish...”及布局预览丢失问题

Hey there, let's work through this annoying issue with your Navigation Drawer XML—stuck on "Waiting for build to finish..." and missing layout preview can be such a roadblock. I’ve dealt with similar glitches before, so here are some practical fixes to try:

  • Force Sync & Clean/Rebuild Your Project
    Build cache corruption is a common culprit here. Follow these steps:

    1. Go to File > Sync Project with Gradle Files and wait for the sync to complete.
    2. Then run Build > Clean Project, followed by Build > Rebuild Project.
    3. Restart Android Studio—this often clears up stuck build processes and preview issues.
  • Verify Your XML File’s Completeness
    The code snippet you shared cuts off at xmlns..., so make sure your activity_main_drawer.xml has no syntax errors or incomplete tags. A standard Navigation Drawer menu structure looks like this:

    <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android">
    
        <group android:checkableBehavior="single">
            <item
                android:id="@+id/nav_home"
                android:icon="@drawable/ic_home"
                android:title="Home" />
            <item
                android:id="@+id/nav_profile"
                android:icon="@drawable/ic_profile"
                android:title="Profile" />
        </group>
    
        <item android:title="Settings">
            <menu>
                <item
                    android:id="@+id/nav_settings"
                    android:icon="@drawable/ic_settings"
                    android:title="App Settings" />
            </menu>
        </item>
    </menu>
    

    Double-check for unclosed tags, misspelled attributes, or missing namespace declarations—these can halt the build and prevent the preview from loading.

  • Adjust Android Studio Preview Settings

    1. If the Preview pane isn’t visible, enable it via View > Tool Windows > Preview.
    2. Make sure the selected API level in the preview dropdown matches a version your project supports (don’t pick one higher than your compileSdkVersion).
    3. Click the Refresh button at the top of the Preview pane to force a reload.
  • Disable Instant Run
    Instant Run can sometimes interfere with build processes:
    Navigate to File > Settings > Build, Execution, Deployment > Instant Run, uncheck Enable Instant Run to hot swap code/resource changes on deploy, then restart Android Studio.

  • Validate Gradle Dependencies
    Ensure your module-level build.gradle has the correct Navigation component dependencies (match versions to your project’s AndroidX setup):

    dependencies {
        implementation "androidx.navigation:navigation-fragment-ktx:2.7.6"
        implementation "androidx.navigation:navigation-ui-ktx:2.7.6"
    }
    

    Sync Gradle after updating these, then try building again.

If none of the above works, try invalidating Android Studio’s caches: Go to File > Invalidate Caches..., check Invalidate and Restart, and let the IDE reload. This fixes many stubborn build/preview issues caused by corrupted cache files.

内容的提问来源于stack exchange,提问作者Dr Mido

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:37:44