androidandroid-studioandroid-resourcesmodularization

Android resources modularization


I have my Android project divided into 5 modules. The 'app' module handles all the views and processing with the UI having all the resource drawables.

Now, I am implementing an algorithm to compare images and the source code must not be in the 'app' module. What is the correct way to access these drawables? I think that to maintain the project architecture I should create/add these drawables in this module, if so... how can I access them? because this only works when the java class is in 'app' module, which I don't want.

bmpimg1 = BitmapFactory.decodeResource(application.getApplicationContext().getResources(), R.drawable.example);

Do I have to add some lines on the gradle files? Thanks in advance.


Solution

  • I solved the issue by adding these lines to the build.gradle of the new module:

    sourceSets{
        main.res.srcDirs = ['src/main/res']
    }
    

    and then the drawables of this module placed in the res/drawable folder were recognized:

    bmpimg1 = BitmapFactory.decodeResource(application.getApplicationContext().getResources(), R.drawable.example);
    

    Thanks.