sodcalculator

10 Tech How-To

Android Studio Error Module Not Specified: Fix

Guide 10-21651 · Updated · Step by step

The “Module not specified” error in Android Studio appears when you try to run or debug an app but the IDE cannot determine which module (usually your app module) should be used as the run target. This fix is straightforward: select the correct module in the run configuration dropdown, or if that fails, sync your Gradle files and invalidate caches.

What Causes the “Module Not Specified” Error?

This error typically occurs in one of three situations:

  • No run configuration selected – Android Studio needs to know which module (e.g., app) to build and launch. If the dropdown next to the Run button shows “No Module” or is empty, you’ll get this error.
  • Gradle sync failure – If your project’s Gradle files have errors or dependencies haven’t downloaded, Android Studio can’t identify available modules.
  • Corrupted IDE cache or project metadata – Sometimes the IDE’s internal state (stored in .idea/ and build/ folders) becomes out of sync with your actual project structure.

Quick Fix: Select the Correct Module

The most common solution is to explicitly choose the module you want to run:

  1. Look at the toolbar at the top of Android Studio. Next to the green Run button, there is a dropdown that shows the current run configuration (e.g., “app” or “No Module”).
  2. Click that dropdown and select Edit Configurations…
  3. In the dialog, under Android App, select your app module (usually named app). If no configuration exists, click the + icon, choose Android App, and name it (e.g., “app”).
  4. In the General tab, under Module, click the dropdown and select your app module (e.g., app).
  5. Click Apply and OK. Now try running again.

If the module dropdown is empty or greyed out, your Gradle sync likely failed. Proceed to the next fix.

Fix Gradle Sync Issues

Gradle sync is what tells Android Studio what modules exist. If sync fails, the IDE cannot see your modules. Here’s how to force a proper sync:

  1. Click File > Sync Project with Gradle Files (or the elephant icon in the toolbar).
  2. If sync fails, check the Build window for error messages. Common issues include network problems (dependencies not downloading), outdated Gradle plugin versions, or syntax errors in build.gradle files.
  3. Try File > Invalidate Caches and Restart…. In the dialog, select Invalidate and Restart. This clears the IDE’s cache and forces a fresh index.
  4. After restart, let Android Studio re-sync the project automatically. If it doesn’t, manually trigger a sync.

When the Module Dropdown Is Empty

If after syncing the module dropdown in the run configuration still shows no options, your project structure may be misconfigured. Check the following:

  • Make sure your settings.gradle file includes the module. It should contain a line like include ':app'.
  • Verify that the module directory (e.g., app/) contains a build.gradle file with the com.android.application plugin applied.
  • If you recently renamed or moved a module, the .idea/modules.xml file may be stale. Deleting the .idea folder (and build folders) and reopening the project will regenerate them.

Why Does This Happen After Updating Android Studio?

Updates to Android Studio or the Android Gradle Plugin can sometimes invalidate existing run configurations. The IDE may lose track of which module is the “active” one. This is not a sign of a broken project – it’s a known quirk. The fix is the same: re-select the module in the run configuration and perform a Gradle sync.

Common Misconception: It’s Not About Your Code

Many developers think this error means their Java/Kotlin code has a problem. It does not. The error occurs before any code is compiled – it’s purely a project configuration issue. You don’t need to change your source files. If you’re seeing this error, your code is likely fine; the IDE just doesn’t know what to build.

Frequently Asked Questions

Why does the module dropdown show “No Module” even after sync?

This usually means the run configuration was created before a Gradle sync, and the IDE hasn’t refreshed the module list. Go to Run > Edit Configurations, select your configuration, and re-select the module from the dropdown. If the dropdown is still empty, close the dialog, do a Gradle sync (File > Sync Project with Gradle Files), and try again.

Can I run a single Kotlin file without a module?

No. Android apps require a module with an Android application plugin. You can’t run a plain Kotlin file as an Android app. If you want to test a small piece of code, create a unit test in your app module instead.

What if I have multiple modules and the wrong one is selected?

In the run configuration, the module dropdown lets you pick which module to build. If you have a library module and an app module, make sure you select the one with the com.android.application plugin – that’s the one that produces an installable APK.

Does deleting the .idea folder lose my settings?

Yes, it removes local IDE settings like run configurations, code style preferences, and window layout. However, these are not essential – you can recreate run configurations easily. Your source code and Gradle files are untouched. It’s a safe last-resort fix when the error persists.

Why does the error appear when I click Run from the menu?

If you use Run > Run ‘app’ and no configuration is selected, Android Studio may default to a configuration that has no module assigned. Use the toolbar dropdown to pick the correct configuration first, or create a new one as described above.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →