简体   繁体   中英

Missing top-level build.gradle in multi-module project

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

在此处输入图片说明

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?

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 .
  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...
// 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, etc

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.

  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".

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()
    }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM