sourceSets for paths not belonging to projects added as dependencies

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.