191

I am getting a 'Module not specified' error in my run config. I have no module showing in the drop down yet I can see my module no probs. The issue came about when I refactored my module name, changed the settings.gradle to new name.

Now when I go to project structure and select my module nothing shows in the screen, not even an error.

I'm not 100% sure, but the icon beside my module looks like a folder with a cup and not a folder with a phone.

My exact steps -

  1. Open in Android view
  2. Refactor directory name
  3. refactor module name
  4. change settings.gradle contents: name to new name
Jon
  • 9,156
  • 9
  • 56
  • 73
Fearghal
  • 10,569
  • 17
  • 55
  • 97

26 Answers26

490

Resync your project gradle files to add the app module through Gradle

  1. In the root folder of your project, open the settings.gradle file for editing.

  2. Cut line include ':app' from the file.

  3. On Android Studio, click on the File Menu, and select Sync Project with Gradle files.

  4. After synchronisation, paste back line include ':app' to the settings.gradle file.

  5. Re-run Sync Project with Gradle files again.

eli
  • 8,571
  • 4
  • 30
  • 40
52

never mind, i changed the name in settings.gradle and synced and then changed it back and synced again and it inexplicably worked this time.

Fearghal
  • 10,569
  • 17
  • 55
  • 97
21

This issue also may happen when you just installed new Android studio and importing some project, in the new Android studio only the latest sdk is downloaded(for example currently the latest is 30) and if your project target sdk is 29 you will not see your module in run configuring dialog.

So download the sdk that your app is targeted, then run Sync project with gradle files.

enter image description here

Pavel Poley
  • 5,307
  • 4
  • 35
  • 66
18

Try to delete the app.iml in your project directory and restart android studio

vidalbenjoe
  • 921
  • 13
  • 37
12

You have 3 ways:

  1. Clean Project in Android Studio menu

Build -> Clean Project and use Build -> Rebuild


  1. Remove all the modules in settings.gradle
  • Open settings.gradle project
  • Remove include ':app' and other modules
  • Sync gradle
  • Add include ':app' and other modules
  • Sync gradle again

  1. Remove all code in gradle.properties
  • Open gradle.properties project

  • Remove all code

    org.gradle.daemon=true

    org.gradle.configureondemand=true

    org.gradle.parallel=true

    android.enableBuildCache=true

  • Sync gradle

  • Add code again

  • Sync gradle again

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Rasoul Miri
  • 11,234
  • 1
  • 68
  • 78
8

None of the existing answers worked in my case (Android studio 3.5.0). I had to

  1. close all android studio projects
  2. remove the project from the recent projects in android studio wizard
  3. restart android studio
  4. use import option (Import project- Gradle, Eclipse ADT, etc) instead of open an existing project AS project
  5. File -> Sync project with gradle files
Nikos Hidalgo
  • 3,666
  • 9
  • 25
  • 39
5

I realized following line was missing in settings.gradle file

include ':app'

make sure you include ":app" module

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
bikram
  • 7,127
  • 2
  • 51
  • 63
5

I struggled with this because I'm developing a library, and every now and then want to run it as an application.

From app/build.gradle, check that you have apply plugin: 'com.android.application' instead of apply plugin: 'com.android.library'.

You should also have this in app/build.gradle:

defaultConfig {
        applicationId "com.your_company.your_application"
        ...
}

Finally run Gradle sync.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Moyote
  • 1,169
  • 9
  • 20
5

check your build.gradle file and make sure that use apply plugin: 'com.android.application' istead of apply plugin: 'com.android.library'

it worked for me

ali ozkara
  • 5,425
  • 2
  • 27
  • 24
  • 1
    Yes but what if your module really is a 'com.android.library' and you're writing an activity beneath androidTest to test it? That's what JW does here: https://github.com/JakeWharton/RxBinding/tree/master/rxbinding-swiperefreshlayout/src/androidTest. There must be a way to run... – Ewan Jan 07 '20 at 11:43
4

If you can't find your settings.gradle file in your project directory

  1. Add settings.gradle file

  2. Add include ':app' inside the settings.gradle file

  3. Rebuild or sync your project

Your app module should appear in your configuration file.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
3

I had the same issue after update on Android Studio 3.2.1 I had to re-import project, after that everything works

Peter
  • 260
  • 5
  • 3
3

I would like to add some more information while I was facing this issue:

Ref: Answer from @Eli:

  1. Cut line include ':app' from the file.
  2. On Android Studio, click on the File Menu, and select Sync Project with Gradle files.
  3. After synchronisation, paste back line include ':app' to the settings.gradle file.
  4. Re-run Sync Project with Gradle files again.

So, let's follow the instruction and try to keep one thing in mind, that what is showing in your build configuration. Make sure you are seeing the name of your configuration app like the image below:

enter image description here

If you are seeing anything else, then the steps mentioned by @Eli (the most accepted answer) will not work.

An alternative Solution If you have a different name on the Run/Debug Configurations window and the above process is not working, please change the config name to 'app'

then -> hit Apply -> then Ok.

After that follow this:-

File->Sync project with gradle files (if needed).

Now check the issue will be resolved hopefully. I have faced this issue and I think it might help others as well.

A S M Sayem
  • 2,010
  • 2
  • 21
  • 28
2

I had to select "Use classpath of module:" drop down option and choose my module.

2

I was trying to open an old GitHub project with the latest android studio that's why got this error. I tried almost all the way that mentions in this post but none of them is work.

In my case, I update my Gradle version with my latest project, and the issue resolved. Use your latest Gradle version to resolve the issue.

enter image description here enter image description here

Md Imran Choudhury
  • 9,343
  • 4
  • 62
  • 60
2

Sometimes the project doesn't load your sdk version. so manually change the this in your build.gradle file module level to your own sdk version

  1. compileSdkVersion 28
  2. buildToolsVersion "28.0.3"
  3. targetSdkVersion 28

now re-sync the your project.

2

If no solution works then make sure that you opened the project from the right directory

For example, when I opened the project from app folder and from the root I got

Module not specified

error, but when I opened it from todoapp the error had gone

example

Islam Ahmed
  • 668
  • 9
  • 19
  • Thanks Islam Ahmed, I found this out myself and came here to add it if needed. In my case I opened the root folder of a fresh repo clone using Android Studio project launcher, instead of clicking down to where the app is. Wasted 30 minutes on it this morning and I feel slightly better that I'm not the only one to do this :) – Pete Baron Aug 30 '22 at 22:21
1

Check your minsdkversion, compilesdkversion and targetsdkversion and ensure that you installed all those from Tools -> SDKManager in Android Studio.

e.g if your targetsdkversion is 30 and minsdkversion is 28, ensure that you installed 28, 29, 30 sdks.

LincyTonita
  • 327
  • 4
  • 14
0

Remove from app gradle this code

android{
    defaultConfig.applicationId="com.storiebox"
}
0

We are currently recommending AS 3.3 for exercises.

These settings will work in the current 3.3 beta version with two small changes to your project:

In build.gradle (Project), change gradle version to 3.3.0-rc02

In menu go to File -> Project Structure. There you can change the gradle version to 4.10.0

pincy
  • 73
  • 1
  • 1
  • 6
0

in my case, when I added Fragment I git this error.

When I opened THe app build.gradle I saw id("kotlin-android") this plugin in plugins.

just remove it!

Sana Ebadi
  • 6,656
  • 2
  • 44
  • 44
0

You can clean your project and and invalidate caches / restart. After that your project might be fixed.

This solution works for me.

  • 1
    "Worked for me" answers are not encouraged. Please try improving this by adding info on how to invalidate the cache and restart. – Phill Healey Nov 22 '21 at 21:05
0

For me the issue and solution:

  • I am using Webrtc library module in my android project. I had updated the compile and targeted sdk version in my gradle for only app module have havent for the webrtc library gradle.
  • Go to SDK Manager and confirm if the sdk version is installed (completely and not partially).
  • After above steps Invalidate & Restart app.
  • In project folder on your windows explorer within your project delete the .idea folder.

Note: Make sure to update your gradle for all module other than app module as well.

Prajwal Waingankar
  • 2,534
  • 2
  • 13
  • 20
0

For my scenario, the fix was simpler. I had accidentally opened my project in Android Studio one folder too high, so it wasn't finding settings.gradle and build.gradle in the root project folder. Once I realized that and opened from the root of my project instead, the Run/Debug configuration came back.

Bryan Bedard
  • 2,619
  • 1
  • 23
  • 22
0

In my 1st case, There was no internet connectivity while I opened the project. After the internet connectivity is back, we just resync the gradle and it works.

In my 2nd case, Also, there may be an issue with the firewall. If there are any firewall restrictions, It could not work. After disabling firewall restrictions and resyncing the gradle, it worked well.

Rumit Patel
  • 8,830
  • 18
  • 51
  • 70
-1

If all above solution doesn't work then do try this solution, because in my case none of the above solution were working. I too was facing this problem and after 5 hour of hard work I am able to tell you a solution. If you are cloning project using git the I would recommend you to directly clone project using android studio. It worked for me.

-2

Run the app, it will show 'Edit Configuration' window. Under Module - select the app (it would be <no module> ).

Then select the activity (under Launch Options)

enter image description here

tanni tanna
  • 544
  • 4
  • 12