1

I am using Android Studio and Gradle to develop an Android application.

I am creating a theme and I got dozen of resource files. So to make my project cleaner I (following this SO answer) moved all theme related files to another folder called res_theme and inside my build.gradle file I added the following to merge the two resource files folders:

sourceSets {
    main {
        res {
            srcDir 'src/main/res_theme'
        }
    }
}

Now when I build my project I get the following error in several resource files:

URI is not registered in resource file

That error occurs in this line:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

Another thing I noticed is this popup message:

'main' in build cannot be applied to '(groovy.lang.Closure)'

in this line: main {

EDIT

Project structure:

AppName
|--------lib
|--------src
         |--------main
                  |--------java
                  |--------res
                  |--------res_theme
                  |--------AndroidManifest.xml
|--------AppName.iml
|--------build.gradle
|--------proguard-rules.txt

If you need more detail please tell me

Community
  • 1
  • 1
letiagoalves
  • 11,224
  • 4
  • 40
  • 66

2 Answers2

0

That sourceSets block needs to be inside your android block.

Scott Barta
  • 79,344
  • 24
  • 180
  • 163
0

It looks like it is not possible.

I've tried next lines:

android {
    compileSdkVersion 19
    buildToolsVersion "19"

    defaultConfig {
       minSdkVersion 9
       targetSdkVersion 16

       versionCode 4
       versionName "1.0.0.6"
    }

    sourceSets {
        main {
            resources {
                srcDirs = ["src/main/res", "src/main/res2"]
            }
        }
    }
}

And I added simple string to res2 folder:

<resources>
    <string name="test1">Test 1</string>
</resources>

And when I simply try to access this string:

setTitle( R.string.test1 );

I got compilation error - can not find symbol variable test1.

You can try to fix this with flavours but I don't think this is right usage of flavours. You can also make library inly for theme but again I don't think this is optimal solution.

Eugen Martynov
  • 19,888
  • 10
  • 61
  • 114
  • first of all thanks for the attention. I am stuck and I can't find any help. why this `instrumentTest.setRoot('src/test')`? – letiagoalves Jan 08 '14 at 15:38
  • also looking at this SO answer it seems it is possible: http://stackoverflow.com/questions/16577782/sub-folders-in-drawable-resource-folder/19859379#19859379 – letiagoalves Jan 08 '14 at 15:39
  • I removed confusing line. And maybe it was but not anymore with new version. I would be much confident about when I will see code of android gradle plugin:) – Eugen Martynov Jan 08 '14 at 16:03
  • Have you seen this: http://tools.android.com/tech-docs/new-build-system/resource-merging ? It really seems it is possible to merge 2 resource folders – letiagoalves Jan 08 '14 at 16:11