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

Android Studio首次构建问题:运行按钮禁用、Gradle同步异常等

Troubleshooting Your First Android Studio Project Issues

Hey there, I’ve seen these exact problems pop up all the time when folks are setting up their first Android Studio project—let’s break down how to fix each one step by step!

1. Fixing the Disabled Run Button & Missing Modules in Run Configurations

These two issues usually go hand in hand, and they’re almost always tied to Gradle not syncing properly or your project structure being misrecognized. Here’s what to try:

  • Double-check your project has a valid module: Switch to the "Project" view (top-left dropdown, switch from "Android" to "Project") and look for an app folder with a build.gradle file inside. If it’s missing, you might have accidentally created an empty project—start over with the "Empty Activity" template, which sets up a valid module automatically.
  • Restart Android Studio completely: Sometimes the IDE gets stuck in a wonky state. Close it fully (make sure no background processes are running via task manager), then reopen it. This often clears minor glitches.
  • Invalidate Caches & Restart: Go to File > Invalidate Caches..., check all three options in the popup, then click "Invalidate and Restart". This wipes out corrupted IDE cache that frequently causes module detection issues.

2. Fixing the Never-Ending Gradle Sync

If your Gradle sync runs forever, it’s typically due to network problems (downloading dependencies) or corrupted Gradle files. Try these fixes:

  • Verify your network connection: Android Studio needs to download Gradle binaries and app dependencies from online repositories. If you’re on a restricted network (like a corporate VPN), switch to a stable public network, or set up proxy settings in File > Settings > Appearance & Behavior > System Settings > HTTP Proxy.
  • Wipe the Gradle cache: Navigate to your user folder—on Windows that’s C:\Users\<YourName>\.gradle, on Mac/Linux it’s ~/.gradle. Delete the caches folder entirely, then go back to Android Studio and re-run File > Sync Project with Gradle Files. This forces a fresh download of all required files, fixing syncs stuck due to corrupted cached data.
  • Use a local Gradle distribution: Go to File > Project Structure > Project, select "Use local gradle distribution", and point it to a Gradle folder you’ve downloaded manually. Make sure the version matches the one listed in your project’s gradle/wrapper/gradle-wrapper.properties file (look for the distributionUrl line).
  • Check for build.gradle errors: Look at the "Build" tab at the bottom of Android Studio—if there are red error messages (like typos, missing plugins, or invalid dependency versions), fix those first. Even a small mistake here can break the entire sync process.

Last Resort

If none of the above works, create a brand new project with the default "Empty Activity" template. If this new project works fine, your original project likely has corrupted files—compare the two projects’ build.gradle files and folder structures to spot what’s wrong.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 09:06:20