Android multi-module under repeated jar package problem

Disclaimer: This article is xing_star original article, please indicate the source!

This article synchronization from http://javaexception.com/archives/166

Android multi-module under repeated jar package problem

Android development, the number of multi-module under repeated jar package or with a lot of the problems encountered. There are many ways to solve one by one under the summary here.

To give an example, our current app architecture, uses a multi-module architecture, component-based architecture is somewhat similar to the way in which a module is Ali rivers, and the other module is Netease cloud letter. These two packages are present fastjson, by the jar package are copied to the libs directory references under way, the two jar package version is also inconsistent, so the compile time to prompt a mistake. We know the causes of the problem, then how to solve. The first way, the two module of the jar are deleted, and then use the remote gradle dependent on a particular version of the way. The second approach, the establishment of a new Common module, store this jar package, reserved the right jar, then Ali Sea and cloud letter moudle rely on the Common module.

Described above two schemes which, I prefer the first, change up easier.

Then next we'll introduce, in another way, in a demand and found that there are two module introduces high moral map sdk, version is also inconsistent, after compiling, the error. How to solve it, do not use this remote-dependent manner, mainly did not find the use of remote-dependent manner. So here, then, the two module jar by comparison, retains a higher version and then the two module use the same jar, so, certainly will still direct the compiler error, you also need to do a module in which processing (another module without treatment).

We can look at the code processing

//    api fileTree(dir: 'libs', include: '*.jar')
    provided files('libs/AMap2DMap_3.0.0_AMapSearch_3.6.1_AMapLocation_3.2.1_20161228.jar')

 

These two lines of code are needed, the first line is under the jar to remove gradle automatically scan libs directory, the second row is provided a way to participate in compiling, so that you can solve the problem.

Finally, in summary, we talked about a total of three treatments multi-module solution jar package under repeated problems. The first is to use a remote dependency, the second is to establish a Common moudle, used to keep the jar package, it references to other module, the third way is to use provided. hope its good for U.S..

 

Guess you like

Origin www.cnblogs.com/xing-star/p/11129311.html