22

I'm missing the "Top-Level" project build.gradle script from my project:

enter image description here

I imported it into Android Studio from a very complex Maven/Eclipse project, and it basically made a module ("android") in the top level of the directory, and added all the submodules ("tappurwear", "shared", etc) into that original module's directory.

I know this is a kind of messed up structure, but there's a lot of other build scripts so I can't really just move all the files into a proper separate module.

So now I'm wondering, how do I add a top-level build.gradle script, for the entire project? The usual Android Studio projects I've seen just have one, but it's treating my top-level build script as the "android" module's build script. Can I create a new build.script to be the top-level project script that shares settings with the other modules? Is there a way I can rename the top-level build script that gets used in all other module scripts, in Android Studio or Gradle?

phreakhead
  • 14,721
  • 5
  • 39
  • 40
  • Which project is top-level? – Sergey Shustikov Jul 19 '15 at 19:57
  • @ssh the "android" module is the build.script in the root level directory. Should i just rename that to something else and make a new build.gradle for the top-level? – phreakhead Jul 20 '15 at 01:15
  • Hi, I'm a bit confused about these two gradle files. I have one in my app/platforms/android and another one in my app/platforms/android/CordovaLib. Now my question is, which one is project-level and which one app-level build.gradle? Can you please help me? – Ionut Necula Sep 28 '16 at 07:57
  • Related post - [Missing project.gradle in Android View](https://stackoverflow.com/q/46230078/465053) – RBT Aug 13 '18 at 08:09
  • 1
    Related answer [Missing project.gradle in Android View](https://stackoverflow.com/a/56165326/6798074) – Ahmed AlAskalany May 16 '19 at 09:39

6 Answers6

22

I had the same issue on my multi-module project, this solution worked for me.

  1. Closed all the open projects.
  2. Removed project from recent projects in "Welcome to Android Studio" window.
  3. Now click "Open existing android studio project" & browse to the project repo & select top level build.gradle.
Vignesh Sundaramoorthy
  • 1,827
  • 1
  • 25
  • 38
  • 1
    It doesn't matter if you have 1 or more submodules. I had this issue with one "app" submodule https://i.stack.imgur.com/RZY1x.png Your steps helped me to solve this problem – user25 Jan 28 '19 at 20:49
  • Thanks. This helped me too. However, no need to delete all projects from the recent project list. Just removing the project having issue resolved this issue – sunil Apr 03 '19 at 07:26
  • This worked, but only after doing a `git clean -dX`. *Ensure you move any `local.properties` and `keystore.properties` etc. out of the way before you do a `git clean`!* – lionello Mar 22 '20 at 12:59
3
  1. close your project
  2. rename the project directory (in the workspace)
  3. open the project with the new name
  4. wait for gradle sync, build.gradle (project) should be added to the Gradle scripts
  5. close the project
  6. rename the project directory with the original name
  7. reopen the project with its good name
  8. wait gradle sync, the build.gradle should be here again...
Christian
  • 748
  • 7
  • 23
1
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.2.3'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}
allprojects {
repositories {
    jcenter()
}
}

It really doesn't matter from my experience, what you need to do is make a build.gradle file, with your favorite .txt writer (make sure it says .gradle). If your root foldere app name is say "Archiver", then you put the gradle file where you see folders like app, .idea, gradle, e.t.c.

One thing you have to keep in mind is that you may need to add a pointer to this gradle if your project can't find it for some reason.

To make sure your project looks good, go to File >> Project Structure >> Module (and every other menu you feel you implemented). If you don't see any red x's then you may be good to go.

Tobi Akerele
  • 962
  • 10
  • 20
1
  1. Close project.
  2. Remove ".idea\project_name.iml" (name are usually same as project folder).
  3. Remove reference to this file from ".idea\modules.xml".
  4. Open project.

IDEA will re-create this file in projec's root folder instead of ".idea" and project-level "build.gradle" appears. This makes me think that better solution could be just moving this file outside ".idea" and correct reference in ".idea\modules.xml".

G-Shadow
  • 188
  • 3
  • 13
0

You can just add build.gradle for root folder which contains gradle.properties and settings.gradle file

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}
Sergey Shustikov
  • 15,377
  • 12
  • 67
  • 119
  • Hi, I'm a bit confused about these two gradle files. I have one in my app/platforms/android and another one in my app/platforms/android/CordovaLib. Now my question is, which one is project-level and which one app-level build.gradle? Can you please help me? – Ionut Necula Sep 28 '16 at 07:54
0

The following steps resolved the issue for me:

  1. Close project.
  2. Remove ".idea\project_name.iml" (name are usually same as project folder).
  3. Remove reference to this file from ".idea\modules.xml".
  4. Open project in IDE
Anil
  • 1