I created a module in Android Studio. In the module code, I want to show a dialog that uses the layout defined in the module. When I reference a layout, for example net.gwtr.module.R.layout.my_dialog_layout , I get this exception;
java.lang.ClassNotFoundException: Didn't find class "net.gwtr.module.R$layout" on path: DexPathList[[zip file "/data/app/net.gwtr.moduletest-1.apk"],nativeLibraryDirectories=[/data/app-lib/net.gwtr.moduletest-1, /vendor/lib, /system/lib]]
I think the reason is that the resources are combined when adding a module to the project. He did not create different resource identifiers for the module package name. Therefore, I cannot get to the resources from the module package.
How can I refer to module resources in a module?
Edit1: I reference the resource as follows:
Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.my_dialog_layout); dialog.show();
Edit2: I found a way, but I do not want to use it every time I refer to a resource.
I can get resources when I get the resource identifier with this;
context.getResources().getIdentifier("my_dialog_layout", "layout", context.getPackageName())
source share