Android Studio:Multiple dex files define Landroid/support/annotation/AnimRes

news/2024/7/24 2:27:07 标签: 移动开发, java

近期真的比較忙,一不小心博客又荒了两个月。

从今天起,决定重返csdn,多多纪录和分享。

先从一个近期被折磨的死去活来的问题。
由于升级了V4包。就一直报这个问题:

com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;

每次都要clean一下,然后才干编译过。光这个过程就浪费了4/5分钟。出现这个问题是由于最新的v4包(compile ‘com.android.support:support-v4:22.2.1’)已经包括了annotation.jar这个包,但其它jar包里也包括这个包造成的。而非同一时候包括了v4/V7造成的,所以一堆人说在v7包里进行例如以下设置:

compile ('com.android.support:appcompat-v7:22.2.1'){
        exclude group: "com.android.support", module: "support-v4"
    }

即设置v7包不包括v4,这个设了也是无用的。

仅仅要确保用v4和v7 的地方版本号一致就可以。

正确的解决方法有例如以下几种:
1,找到项目其它的依赖包。一定在libs里的某个jar包里。隐藏着annotation.jar包,将其删掉就ok了。此为最正统的解决方法。
2,降级v4包。由于高版本号的v4才包括annotation.jar,能够在最外面的build.grable里强制设置:

allprojects {
    repositories {
        jcenter()
    }
    configurations.all {
        resolutionStrategy.force 'com.android.support:support-annotations:22.1.0'
    }
}

3,在须要v4包的地方exclude掉annotation包。注意compile要多加个括号:

 compile ('com.android.support:support-v4:22.2.1'){
        exclude module: 'support-annotations'
    }

缺点是每一个用v4包的地方都要这么设置下。
4。在application的build.gradle里的dexOptions设置里添加一句:preDexLibraries = false就ok了:
这里写图片描写叙述

PS:以上四种方法都能够解决这个问题,推荐正统的方法1和偷懒的方法4。


http://www.niftyadmin.cn/n/842130.html

相关文章

qt搭建环境

1 用viewteam实现远程控制电脑。可以在家里继续操作办公电脑了。 http://blog.csdn.net/sch0120/article/details/38324599   2qt环境安装。今天出现了 qmake错误。 是环境配置的问题 设置环境变量 注意: 根据具体安装路径设置环境变量中的路径 1) 将 D:\QT\qt-4.…

JSP与Servlet做登录验证

JSP用于显示&#xff08;客户端交互&#xff09;&#xff0c;Servlet用于做数据处理 JSP页面代码&#xff1a; <% page language"java" contentType"text/html; charsetutf-8"pageEncoding"utf-8"%> <!DOCTYPE html PUBLIC "-//…

Error in created hook: “ReferenceError: keyword is not defined“

vue使用ajax 报错 Error in created hook: “ReferenceError: keyword is not defined” 非常低级的错误&#xff0c;可能是因为请求中的请求参数未定义异常导致的&#xff0c;但是他不会报错未定义&#xff0c;只会报错关键字未定义。

阿修罗监控与grafana结合使用

环境准备一、安装grafana按自己习惯创建安装目录&#xff0c;本文在当前目录 #cd#wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.3.2.linux-x64.tar.gz --no-check-certificate#tar xzvf grafana-4.3.2.linux-x64.tar.gz #cd grafana-4.3.2/co…

HDU 5183 Negative and Positive (NP)

HDU 5183 Negative and Positive (NP) 思路&#xff1a;维护一下前缀和&#xff0c;从后往前向set里面插入前缀和&#xff0c;然后查找sum[i-1](-1)i1*k在不在set里面。 代码&#xff08;快读set&#xff09;&#xff1a; 1466ms险过&#xff0c;用hash表应该快一点。 #include…

Windows Server 2012 NIC Teaming 网卡绑定介绍及注意事项

Windows Server 2012 NIC Teaming 网卡绑定介绍及注意事项 转载自&#xff1a;http://www.it165.net/os/html/201303/4799.html Windows Server 2012 NIC Teaming 也称作 负载平衡/故障转移 &#xff08;LBFO)。主要功能就是带宽聚合&#xff0c;负载均衡以及故障转移。Windows…

uniAPP中使用tabbar时,created和destroyed无效

使用tabbar时&#xff0c;created不管如何切换tabbar&#xff0c;都只加载一次。这时我们就需要通过监听路由。来模拟代替他们的功能。 watch: {$route(){console.log("成功&#xff01;")let that this;if(非定时器页面){clearInterval(that.timer_interval);that…

mac Java环境配置

1&#xff09; 安装JDK 6或者JDK 7 或者JDK8 mac 的 参看http://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html 大家在windows里面配置JDK环境变量很容易&#xff0c;但是如果要在mac里面配置JDK环境变量和windows里面有所不同&#xff0c;具体…