问题
NOTE: This question is based on the answers I received in the following discussion:
Android: 2 aar libraries with the same package
In my android projects, I'm trying to support multiple versions of a common codebase used throughout different aar libraries which supposed to compile together on my app. I currently make copies of the classes in the common codebase, changing their package name and put them in every library I create. In the short term, it allows every library to compile with a unique package name. In addition, if a different implementation is required for the classes in the common library, it allows it. In the long term, it creates obvious maintenance problems. I'm trying to create a solution that will allow me to compile multiple libraries with different versions of the same codebase.
I have tried the following process:
Compile my common codebase in an aar library called "commonLib_1_0_0".
Write a library using libCommon_1_0_0 called "libA".
Change the implementation of a method in the common codebase so it includes different code and therefore different version - "comonLib_1_0_1"
Write a library using libCommon_1_0_1 called "libB".
Create a new application implementing both aars.
When I try to compile the application from step 5, an error is thrown:
"Program type already present: commonlib.mybcommonpackage.MyCommonClass"
.
The error is thrown because the compiler can't compile two different classes using the same name and the same package. My question regards to the best way to maintain this situation:
What is the correct way to compile 2 different libraries which use the same common library with different implementations?
Consider that the compiler cannot compile 2 different classes with the exact same name, how should I deploy the common lib in multiple projects?
NOTE: Although I currently use the aar solution to deploy my libs, I also consider to change it for a solution that will help me maintain my code better, according to the needs described in the question.
来源:https://stackoverflow.com/questions/57572278/android-how-to-manage-common-codebase-in-multiple-libraries-used-by-the-same-ap