3

I have a base feature module, and a feature module (you could call it the "child"). The base feature module has a strings.xml file asset containing:

<resources>
   <string name="app_string">Test String</string>
</resources>

I attempt to reference this string resource in the "child" feature's activity, as below:

int resId = R.string.app_string;

Android Studio appears to respect this reference, and will even direct me to the app_string resource when I click it. However, during compilation, I am met with the following error message:

Error:(13, 25) error: cannot find symbol variable app_string

The build Gradle file for my "child" feature has the dependency too:

dependencies {
   ...
   implementation project(':base')
}

I also tried compile project(':base'), but no success.

Is there something blatant that I am missing?

Tyler Ritchie
  • 170
  • 1
  • 9

1 Answers1

8

Your base and child modules have different package names - let's say they are com.example.base and com.example.child. Each contains its own set of resources, and their identifiers will be collected in separate R packages:

  • com.example.base.R
  • com.example.child.R

Because you're trying to access a resource defined in base module, you need to reference it with the fully qualified name of the variable, which is com.example.base.R.string.app_string.

ibrahimkarahan
  • 475
  • 2
  • 9
  • I attempted that, but unfortunately I'm getting `Cannot resolve symbol 'R'`. If I were to use the packages you listed, I would be trying: `int resId = com.example.base.R.string.app_string` as you said. – Tyler Ritchie Jun 22 '17 at 03:08
  • Oh that's interesting, I solved it using `com.example.R.string.app_string` (note, I left out the `base` directory in that path) – Tyler Ritchie Jun 22 '17 at 03:10