本文解决方法参考:《Android开发艺术探索》 以及 http://blog.csdn.net/yuanzeyao/article/details/41809423一、报错截图:
![](https://img-blog.csdn.net/20161204130234585?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
二、解决方案:
错误原因及更深层次的解决方案可以在最上面留的链接或者参考书中找到。本文只记录我所使用的解决方法。一共只需4步,涉及到build.gradle及AndroidManifest.xml两个文件。
1、删除掉项目中未使用过的jar包。
2、项目目录下build.gradle 下的defaultConfig添加multiDexEnabled true
defaultConfig{
multiDexEnabled true
}
3、项目目录下build.gradle 下的dependencies
dependencies{
compile "com.android.support:multidex:1.0.0"
}
4、AndroidManifest.xml中添加 android:name = "android.support.multidex.MultiDexApplication"
如果项目中已经使用了Applicaiton可以提供的解决方法是让自己的Application继承MultiDexApplication或者在Application的attachBaseContext方法中添加
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}