Android: Project 'MyProject' not found in root project 'MyProject'

46,827

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 named a.
  • In branch feature/b there was no module a.

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.

Share:
46,827

Related videos on Youtube

daveomcd
Author by

daveomcd

Learning to code.

Updated on August 04, 2022

Comments

  • daveomcd
    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
    daveomcd almost 11 years
    thanks! it says Task 'build' not found in root project 'MyProject' -- not sure what it means right now googling it.
  • xxstevenxo
    xxstevenxo almost 11 years
  • daveomcd
    daveomcd almost 11 years
    thanks, 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
    daveomcd almost 11 years
    Update: 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
    xxstevenxo almost 11 years
    Hmm.. 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
    daveomcd almost 11 years
    Yeah 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
    xxstevenxo almost 11 years
    No luck trying to figure this out?
  • daveomcd
    daveomcd almost 11 years
    Nope 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
    AlexAndro over 6 years
    In my case I put directly app. Like gradle -q dependencies app:dependencies --configuration compile
  • Bernardo Ruz
    Bernardo Ruz about 3 years
    This 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 error Project 'MyProject' not found in root project 'MyProject' any suggestions?

Related