Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't programmatically get resource from another module

I have an android project with several gradle modules. Dependencies beetween modules look like this:
app <-- coremodule <-- featuremodule

There are a resources in coremodule (strings and colors).

When I use them in layout from featuremodule everything is OK, they are avaliable and work as expected. But when I try to get them programmaticully in Activity from featuremodule I get an exception: Unresolved reference: R

So android:text="@string/res_from_core_module" works and myTextView.setText(R.string.res_from_core_module) doesn't work.

Have anyone ideas why it happens and how to solve this?

like image 553
Mikhail Sidorov Avatar asked May 29 '26 22:05

Mikhail Sidorov


1 Answers

The reason for such behavior was adding 'coremodule' dependency with compileOnly.

build.gradle for app module looked like:

dependencies {
    ...
    compileOnly project(path: ':coremodule')
    ...
}

if change compileOnly with implementation (or api) everything is OK

dependencies {
    ...
    implementation project(path: ':coremodule')
    ...
}
like image 145
Mikhail Sidorov Avatar answered Jun 01 '26 12:06

Mikhail Sidorov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!