KickingLettuce KickingLettuce - 4 months ago 14
Android Question

Android Project Structure is incorrect; only one build.gradle

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?

Answer

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.