sourceSets for paths not belonging to projects added as dependencies

Hi, I have tried to clarify this issue in threads but no successful responses so I am opening as a bug., Check for reference:

It seems that there is not way to specify as sourceSet any folder containing resources if it is not included in a project added as a dependency. I have tried all these combinations with no success:

sourceSets {
    main.resources.srcDirs += '/home/username/AndroidStudioProjects/Lib1/lib1/src/main/res/values'
    main.resources.srcDirs += new File("/home/username/AndroidStudioProjects/Lib1/lib1/src/main/res/values").absolutePath
    main.resources.srcDirs += new File('/home/username/AndroidStudioProjects/Lib1/lib1/src/main/res/values').absolutePath
    main.resources.srcDirs += new File(new URI("file:///home/username/AndroidStudioProjects/Lib1/lib1/src/main/res/values")).absolutePath
    main.resources.srcDirs += '../../Lib1/lib1/src/main/resources/values'
    main.resources.srcDirs += '../../Lib1/lib1/src/main/res/values'
    main.resources.srcDirs += '../../Lib1/lib1/src/main/resources/xml'
    main.resources.srcDirs += '../../Lib1/lib1/src/main/assets'
    main.resources.srcDirs += 'project(Lib1).sourceSets.main.srcDirs'
    main.resources.srcDirs += 'project(:Lib1).sourceSets.main.srcDirs'
    main.resources.srcDirs += 'project(:..:Lib1).sourceSets.main.srcDirs'
}

So, I would apply for either:

  • confirmation as a bug
    
  • confirmation of a intentionally excluded case and amendment of sourceSets documentation and/or warning in code
    
  • clarification of the possible syntax and external locations that can be used as sourceSet paths in documentation
    

Thanks

More on this. Take in mind that Lib1 is not added as a dependency.


  • when I add to build.gradle:

    sourceSets {
    main.resources.srcDirs += ‘…/…/Lib1/lib/src/main/res/values’
    }

  • I get in android Studio a new folder ‘resources’, at the level of ‘res’ folder for the project contaning the expected additions. good
  • however, if i reference in java code a string myvariable defined in this just added folder, compilation fails with:

    :app:generateFlavourDebugAndroidTestSources UP-TO-DATE
    :app:processFlavourDebugJavaRes UP-TO-DATE
    :app:compileFlavourDebugJavaWithJavac
    myclass.java:46: error: cannot find symbol
    getStringResource(R.string.myvariable),
    ^
    symbol: variable myvariable
    location: class string

  • if I add

    sourceSets {
    flavour.resources.srcDirs += ‘…/…/Lib1/lib/src/main/res/values’
    }

same happens, new folder shown in Android Studio and same compilation error in gradle


  • if I add

    sourceSets {
    main.res.srcDirs += ‘…/…/Lib1/lib/src/main/res/values’
    }

no new folder or files in the Android Studio project hierarchy and compilation fails as expected.

So, no idea what is going on with external references. Why the Android Studio Project hierarchy does not show the exact classpath used in compilation by gradle for this flavour? Is this something ok to do for gradle? Android Studio somehow thinks so.

tested with

classpath ‘com.android.tools.build:gradle:1.5.0’

and same is happening

For the moment, I just did a nasty hack of duplicating the resources from these folders/libraries on the project.