2

I have an incorrect project structure. I need a top-level build-gradle, and a module on the same level that contains its own build.gradle.

See picture of how it is organized now. What you see is almost two different levels merged into on.e The build.gradle here is the only one in the project. The one you see has the note that it is the top-level version.

enter image description here

What is the correct way to straighten this out? Do I need to reimport or can I reorganize it?

Other info, I have Gradle 2.10 installed.

EDIT: MORE INFO

Usually I have my top-level Gradle file that contains something like this:

// 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:2.1.2'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

But in the setup above, without having that second Gradle file, where do I put the other info ... for example:

apply plugin: 'com.android.application'


repositories {
    mavenCentral()
    maven {
        url "https://jitpack.io"
    }
}



android {

   defaultConfig {
       // edited
   }

    dependencies {
       // edited
    }


    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

apply plugin: 'com.google.gms.google-services'

When I run the program, I get this error:

Error:A problem was found with the configuration of task ':checkDebugManifest'.
> File 'C:\--\src\main\AndroidManifest.xml' specified for property 'manifest' does not exist.

Is this related?

TheLettuceMaster
  • 15,594
  • 48
  • 153
  • 259
  • did you import an eclipse project? – nupadhyaya Jul 31 '16 at 21:00
  • @Nikhil I believe that is what this was originally. I have been using it in its current state for a while and publishing updates. But I tried to change some things up and noticed some issues when I was working on the gradle files. – TheLettuceMaster Jul 31 '16 at 21:21
  • It's definitely fixable, but I missed the point so I don't know in which direction you'd like to go. Why don't you like the way it is? I think it's artificial to have an extra gradle file like what AS wizard does. Have you tried creating a new project and mimmicking it's structure? – Fabio Aug 05 '16 at 14:05
  • Why do you even have a `gen` folder? – EpicPandaForce Aug 05 '16 at 14:06
  • @EpicPandaForce looks like eclipse inheritance – Fabio Aug 05 '16 at 14:07
  • @Fabio just updated the question with a lot more info. – TheLettuceMaster Aug 05 '16 at 14:54
  • I'd suggest to create an empty project similar to your needs, then just copy the sources and resources manually. It's dirty, but it always works and you end up with a proper structure. Everytime I mess with scripts to try to fix things it all ends up taking a lot of time. – rupps Aug 05 '16 at 15:01

3 Answers3

3

This way is still assuming a flat hierarchy without the extra module asked by OP, but since it's based on my own Eclipse to AS migration I know it worked... for me.

To recognize eclipse defaults without moving the files you need this:

android {
  defaultConfig {

     sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
        }
        test.java.srcDirs = ['src/test/java', 'build/generated/source/debug']
    }

This will most likely allow you to use both eclipse and Android Studio with the same folders in place.

The second way is about not changing gradle but moving folders so gradle finds things where it expects to.

  1. move AndroidManifest.xml, it must go into src/main
  2. move res into src/main/res
  3. move src/com into src/main/java/com (can you confirm where is your com folder currently?

You can either move files or direct gradle to where they are, it's your choice - but don't do both. The only step I don't remember is the build/generated/source/debug for test, I can't remember if I used that because I use groovy or if it was another eclipse maven/AS gradle mismatch.

Fabio
  • 2,654
  • 16
  • 31
  • @KickinLettuce Just to make it clearer, this solution involves only 1 gradle file in the whole project. Even if you want to have 2 I'd rather start this way and leave the 2nd gradle file as a second step. If you can successfully compile everything I can update the answer for it later. – Fabio Aug 05 '16 at 15:18
  • Yes thank you. If 1 gradle file is a legitimate way to go, I'm good with that. I think I misunderstood the error message I was getting. I'll mark this correct because it compiles now. Thanks again! (Also, I think I had that code in the project at one time because the project did compile correctly in the past. I may have took out when I was cleaning things up) – TheLettuceMaster Aug 05 '16 at 17:01
  • if you still want let's convert it to 2 gradle files and a module in the next steps. I'd also clean the answers a little bit if you confir it's doing all the compiling/importing – Fabio Aug 06 '16 at 00:19
  • Nope, it's all good. The app compiles and I am moving on to other things now. Thanks! – TheLettuceMaster Aug 06 '16 at 00:47
  • @KickingLettuce award the answerer the 150 rep please – Ali Bdeir Aug 09 '16 at 07:01
1

It's because Gradle looks for AndroidManifest in a default place --> App/src/main/AndroidManifest.xml

enter image description here

You can define where Gradle can search for your AndroidManifest. How to tell Gradle to use a different AndroidManifest from the command line?

Community
  • 1
  • 1
mmBs
  • 8,421
  • 6
  • 38
  • 46
1

select "android" from the drop down menu instead of "project"

This option

M. Davis
  • 669
  • 2
  • 10
  • 17
Deep Gupta
  • 11
  • 1