There are two applications (projects) that use the same library (a project with the Android Library module).

enter image description here

The App communicates with USB_Lib by direct calling methods, and USB_Lib with the App via the interface with a callback. When applications are working one by one, everything is in order, but when both are launched, then a conflict over access to the resource (USB) begins. Moreover, it became necessary to launch App2 when launching App1 and to switch them by flipping through the screen. The first thing that came to mind is to expand the interface USB_Lib for App2

enter image description here

but somehow the bones turn out: transmit and analyze the contents of the received data from USB_Lib twice , and the module itself should work with only one application.

I decided to go another way:

enter image description here

and import App2 into the App1 project.

This raises the question of how to build one application, the project of which consists of one library module and two application modules with different packages, and do you need to write something else in the gradle in this case? The main thing is to preserve the autonomy of the App2 project, i.e. open the project, fix the code and debug. App1 will always contain App2 and run it depending on the settings, but App2 should be able to work as a separate application. In any case, the device is installed either only App1 (with embedded App2), or only App2.

Who has any ideas?

PS: I considered the option to make USB_Lib as a Service, but there is no need to keep it in memory all the time, and it will turn out like along the interface extension path, though ..

  • The service is not obliged to hang in the memory, and even more so to constantly work - it can be started at the request of any of the parties and close when there is no connection to it. Read about associated services: developer.android.com/guide/components/services?hl=en . But neither one nor the other will work for you if both applications need to be independent (when APP2 does not require APP1 on the device and vice versa) —in this case, the USB access conflict itself must be resolved. - woesss
  • About the "independence" I will clarify: on the device, either only App1 with embedded App2, or only App2 can be installed. - karloson2

0