2

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.

4

1 回答 1

2

我通过将这些行添加到新模块的 build.gradle 解决了这个问题:

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

然后识别出放置在 res/drawable 文件夹中的该模块的可绘制对象:

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

谢谢。

于 2018-03-14T18:54:18.380 回答