Android: How to manage common codebase in multiple libraries used by the same application

醉酒当歌 提交于 2019-12-10 16:17:21

问题


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:

  1. Compile my common codebase in an aar library called "commonLib_1_0_0".

  2. Write a library using libCommon_1_0_0 called "libA".

  3. Change the implementation of a method in the common codebase so it includes different code and therefore different version - "comonLib_1_0_1"

  4. Write a library using libCommon_1_0_1 called "libB".

  5. Create a new application implementing both aars.

  6. 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:

  1. What is the correct way to compile 2 different libraries which use the same common library with different implementations?

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!