Android Project Structure is incorrect; only one build.gradle

后端 未结 3 2017
北海茫月
北海茫月 2021-01-21 17:32

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 h

相关标签:
3条回答
  • 2021-01-21 17:59

    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.

    0 讨论(0)
  • 2021-01-21 18:20

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

    This option

    0 讨论(0)
  • 2021-01-21 18:25

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

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

    0 讨论(0)
提交回复
热议问题