Search code examples
androidgradlemodulepackageresources

How to get resources from modules in android?


I have the main package "app" and module: "theme".

How can I get resources from the module (R.drawable....)?

settings.gradle have include ':theme'

and app build.gradle: implementation project(': theme')

The app can see functions from module, but can't find correct resources. I have tried to import in class file the module, but it can't fiend path to module.


Solution

  • Add in build.gradle.kts like this

    **kotlin

    implementation(project(mapOf("path" to ":theme")))
    

    Declare in settings.gradle.kts

    include(":theme")
    

    Sync and Rebuild the project. if already done so ignore it.

    Now you want to use Resource path from "theme"

    for example : your "theme" module package name like this com.theme.demo so your drawable image set like this

    imageView.setImageResource(com.theme.demo.R.drawable.myImage)
    

    that's it.