一、错误信息如下:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/alibaba/fastjson/JSONStreamAware;
今天把项目从 Windows 本迁移到 Mac 后,编译运行,Android Studio 便报了如上所示的错误。于是开始搜索查询解决方案。由于引发 transformClassesWithDexForDebug 这个错误的原因有很多,网上大家遇到问题也都大同小异,解决方案不尽相同。试了几个网上提供的解决方案后都无济于事。于是,思考,从错误日志下手,又仔仔细细的读了一遍报错信息后,找到了问题的突破口 :
com.android.dex.DexException: Multiple dex files define Lcom/alibaba/fastjson/JSONStreamAware;
于是,去检查项目中与 fastjson 有关的内容。猜测 jar 包冲突,两个地方都引用了 fastjson 。果然,发现不仅 build.gradle 中引用了 fastjson,而且 app 下的 libs 中也存在一份 fastjson 的 jar 包,且二者版本不一致。于是删掉 libs 中的fastjson 的 jar 包后,重新编译运行,问题完美解决~
二、错误信息如下:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat
$AccessibilityServiceInfoVersionImpl;
今天把项目从 eclipse 迁移到 Android Studio 后,编译运行,Android Studio 便报了如上所示的错误。于是开始搜索查询解决方案。由于引发 transformClassesWithDexForDebug 这个错误的原因有很多,网上大家遇到问题也都大同小异,解决方案不尽相同。于是,思考,从错误日志下手,又仔仔细细的读了一遍报错信息后,找到了问题的突破口 :
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat
$AccessibilityServiceInfoVersionImpl;
于是,根据之前的经验,去检查项目中与 v4 包有关的内容。猜测 jar 包冲突,两个地方都导入了 v4 包。果然,发现不仅 build.gradle 中引用了 v4 包,而且 app 下的 libs 中也存在一份 v4 包,且二者版本不一致。于是删掉 libs 中的 v4 包后,重新编译运行,问题完美解决~
不同的错误日志,却是相同的错误原因。吸取教训,以后导入、移植项目时,要更加细心、考虑周全。