问题集锦——(一)Android Studio的Gradle添加重复依赖的问题

来源:互联网 发布:python马踏棋盘算法 编辑:程序博客网 时间:2024/06/05 10:55

报错:

Multiple dex files define Lcom/nineoldandroids/animation/Animator$AnimatorListener;

在Android Studio里build项目时不会报错,但是run项目的时候就会报上面的那个错误

当Module里 添加的依赖和app.build.guild里添加的依赖重复时就会报错

一、解决方案

compile('com.mxn.soul:flowingdrawer-core:1.2.0')compile('com.rengwuxian.materialedittext:library:2.1.4') {        exclude group: 'com.nineoldandroids'}

flowingdrawer-core这个依赖里的libs文件夹下有nineoldandroids2.4.0.jar这个jar包。
materialedittext这个依赖里的gradle里compile ‘com.nineoldandroids.library:2.4.0’
所以会导致重复引用了jar包。在materialedittext的依赖里添加语句 exclude group: ‘com.nineoldandroids’,意思是编译的时候将group为com.nineoldandroids的所有library都去除在外,这样materialedittext就会自动去引用flowingdrawer-core项目里的nineoldandroids2.4.0.jar包了。

不过,我又进行了其他的尝试,我改成如下配置

compile('com.mxn.soul:flowingdrawer-core:1.2.0'){       exclude group: 'com.nineoldandroids'}compile('com.rengwuxian.materialedittext:library:2.1.4') 

这样还是会出问题。想了想,应该是exclude语句只能在编译时将gradle文件里的依赖去除掉,而不能去掉libs文件里的jar包引用。

原创粉丝点击