-1

In my Android app I want to have subdirectories in res/layout. Of course Android doesn't support this itself, so I try to configure Gradle to do this.

My project structure:

src/
    /package_with_java_source
res/
    /drawable
    /layout
           /someLayDir

Now I want to gradle merge this subdirs for me and build project:

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        assets.srcDirs = ['assets']
        res.srcDirs =
                [
                        'res/layout/someLayDir',
                        'res/layout',
                        'res'
                ]
    }
}

Unfortunately when I try to build project I get error:

Error:(29, 60) Gradle: error: cannot find symbol variable app_bar

app_bar is my layout id (R.id.app_bar). Please help me :(

P.S. If it is important I use Intellij Idea 14

kubut
  • 315
  • 5
  • 16
  • Don't do that. The structure under `layout/` is defined by Android proper, not gradle. Android interprets it, so anything you configure into Gradle isn't going to make Android understand what the heck you are doing. It might be better to describe what you are trying to accomplish. – Jeffrey Blattman Jul 30 '15 at 15:33
  • @JeffreyBlattman : I trying to define some hierarchy in my layout files. Something like here: [link](http://stackoverflow.com/questions/4930398/can-the-android-layout-folder-contain-subfolders) – kubut Jul 30 '15 at 15:40

1 Answers1

1

res.srcDirs points to an array of resource root directories. Neither res/layout/ nor res/layout/someDir are resource root directories.

Here, by "resource root directories", I mean that the build tools will expect to see typical resource directories (e.g., drawable-mdpi/, layout/) as immediate children of the roots. In your case:

  • res/layout/ does not have res/layout/drawable-mdpi/, or res/layout/layout/, or anything like that

  • res/layout/someDir/ does not have res/layout/someDir/drawable-mdpi/, or res/layout/someDir/layout/, or anything like that

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • So how can I define hierarchy of my layout files? – kubut Jul 30 '15 at 15:53
  • @kubut: I am not aware of any recipe for what you are seeking ("I want to have subdirectories in res/layout"). – CommonsWare Jul 30 '15 at 15:54
  • So maybe is other way to manage layouts files? Really I must have all in the same dir? It doesn't smell like nice solution... But of course I may be wrong, becouse I have no experience with Android development... – kubut Jul 30 '15 at 15:59
  • @kubut: "Really I must have all in the same dir?" -- that is far and away the simplest solution. "So maybe is other way to manage layouts files?" -- a typical solution is to use a naming convention, such as a prefix, on the filenames, to help cluster related files together. – CommonsWare Jul 30 '15 at 16:01