Android: Project 'MyProject' not found in root project 'MyProject'
Solution 1
Delete .gradle
folder in your project's root folder and resync gradle from Android Studio.
Solution 2
I had the same issue, which happened after switching Git branches:
- In branch
feature/a
I had a Gradle module nameda
. - In branch
feature/b
there was no modulea
.
After I switched from feature/a
to feature/b
, I received the following build output:
Project 'a' not found in root project 'MyApp'
It seems that Android Studio didn't sync with Gradle files after switching to another branch.
So File
-> Sync Project with Gradle Files
resolved the issue.
Solution 3
Assuming your'e using Windows, open command prompt
and navigate to your project root and run gradlew build
to see the error in more detail
cd \androidstudio\MyProject
gradlew build
or run stacktrace with
gradlew build --stacktrace
Duplicate answer can be found here Android Studio: Where is the Compiler Error Output Window?
Solution 4
If people are still having problems:
I had this happen to me and it was because I renamed my app directory manually when trying to rename my project. projects\Hello World\app should be there, and it contains build, libs, src folders, and some files. If it is called something else then renaming it to app through Windows explorer might fix it.
Solution 5
I have the same problem. Just go to your settings.gradle in MyProject directory (i.e. root) and change file like..
include ':app'
rootProject.name = "MyProject"
and then invalidate the cache and restart the project from the file menu.
Related videos on Youtube
Comments
-
daveomcd over 1 year
I'm currently using Android Studio and I'm trying to do a rebuild but I get the following error.
Gradle: FAILURE: Build failed with an exception. * What went wrong: Project 'MyProject' not found in root project 'MyProject'. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
I would attempt the "Try: run with --stacktrace" but, I'm unsure how to do this. Can anyone help my troubleshoot this problem? Thanks!
-
daveomcd almost 11 yearsthanks! it says Task 'build' not found in root project 'MyProject' -- not sure what it means right now googling it.
-
xxstevenxo almost 11 yearstry this link also stackoverflow.com/questions/14093024/…
-
daveomcd almost 11 yearsthanks, after looking at both i decided to close studio and reopen. Now the rebuild worked, but it says
Error running MyProject-MyProject: Module is not found
... so looking into that now. -
daveomcd almost 11 yearsUpdate: Noticed that my Project folder has a blue square on it's icon, but the folder with the same project name within doesn't. If I create a new project it does however. Not sure if this is useful information or not.
-
xxstevenxo almost 11 yearsHmm.. I'm not too sure about that, both my folders have a blue square on them. Are you able to run gradlew build on a new project? (ie. MyProject2)
-
daveomcd almost 11 yearsYeah I'm able to do that. I might just create a new project and move the code over (it's not much); however, I would have liked to solve it in case someone came across the same thing later.
-
xxstevenxo almost 11 yearsNo luck trying to figure this out?
-
daveomcd almost 11 yearsNope just created a new project and migrated it over. ;-/ I still have the old one in case someone has any ideas in hopes of getting this answered though.
-
AlexAndro over 6 yearsIn my case I put directly
app
. Likegradle -q dependencies app:dependencies --configuration compile
-
Bernardo Ruz about 3 yearsThis partially solves my problem. If I
Sync Project with Gradle Files
in branch A, solves the problem for Branch A. I then checkout branch B and get the same error in branch B - so I do the same (Sync Project with Gradle Files
) and it fixes the problem for Branch B. But if I go back and checkout Branch A, I get the original errorProject 'MyProject' not found in root project 'MyProject'
any suggestions?