'How to solve problem Android Application Bundle(AAB) duplicate class?

premise:
In the main project other people have import cronet, and wrote some code, let's call it feature A

implementation "com.google.android.gms:play-services-cronet:16.0.0"

Then I build cronet source code and imported (cronet-api.jar cronet-xxx.jar libcronet.so) into my dynamic feature module, and wrote some code, which we call this feature B

question: then I package the aab format, there is a error message

Execution failed for task ':app:transformClassesWithByteXForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: We found duplicate org/chromium/net/BidirectionalStream class files in the project.
   Failed to resolve class org/chromium/net/BidirectionalStream.class[

I add the following code to build.gradle in the main project, which can be packaged and compiled by aab:

configurations.all {
                exclude group: 'com.google.android.gms', module: 'play-services-cronet'
 // I am not sure, will firebase use this cronet? if I exclude is firebase works well?
            }  

!!! More questions arose:
#################
Suppose, the Cronet Module in aab format needs to be loaded after about 3 seconds after the App is started.
At this time, when feature A calls the code in cronet, it will appear that the class org.chromium.net.xxx cannot be found

#################

If 3 seconds have passed, the CronetModule is already loaded
Function A calls the code in cronet and everything works fine

#################
issues that need resolving:
How to resolve problem that feature A can't find class(org.chromium.net.xxx) (assuming we can't put the cronet module in the main project)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source