android studio 2.3 multidex,Android Studio 升级为3.0后出现 MultiDexMerger 以及解决方案

Note:  以下问题为本人亲测、亲自踩坑、探寻解决方案之路 中遇到的奇怪的问题、错误的方案、正确的方案记录

一、run app 出现问题 如下:Error:Error converting bytecode to dex:

Cause: Dex cannot parse version 52 byte code.

This is caused by library dependencies that have been compiled using Java 8 or above.

If you are using the 'java' gradle plugin in a library submodule add

targetCompatibility = '1.7'

sourceCompatibility = '1.7'

to that submodule's build.gradle file.

这个问题是:compile xxxxxx.v1.0.3 后,出现的问题,大致提示的是依赖的使用了Java8或更高的版本,提示要更改所依赖的submodule java version.排查问题步骤一:

新建一个新项目,将 compile xxxxxx.v1.0.3  添加并依赖到项目中,run 运行Ok,没有任何错误信息。所以推测是所依赖的AndroidStudio环境与当前项目的环境不一致导致的排查问题步骤二:

查看compile xxxxx.v1.0.3的 project setting 查看项目的版本 与 当前的项目不一致;

有查看到这样的日志:

solution is to recompile the class from source using an up to date compiler and without specifying any type options the consepquence of ignoring this warning is that reflective operations on this class will incorrectly indicate that it is not an inner class

翻译为:解决方法是使用最新的编译器从源代码重新编译类,而不指定任何类型的选项忽略此警告的结果是对此类的反射操作将错误地指示它不是内部类

所以:我将当前项目的Gradle version 和 Android plugin version 更改为与 compile xxxxx.v1.0.3相一致。排查问题步骤三:

这样之前的问题是解决了,但是run 运行又出现了新问题:

ignoring innerClasses attribute for an anonymous inner class

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

> java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

翻译为:忽略匿名内部类的innerClasses属性

> java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex排查问题步骤四:

目前已经锁定问题:“是AndroidStudio开发的环境不同导致的,目前项目中的是使用 GradleVersion 4.0.1” plugin version 2.3.3,而 compile中使用的是 GradleVersion 4.0.1 plugin version 3.0.1.

开始解决问题排查问题步骤五:

Error:Error converting bytecode to dex:

Cause: Dex cannot parse version 52 byte code.

This is caused by library dependencies that have been compiled using Java 8 or above.

If you are using the 'java' gradle plugin in a library submodule add

targetCompatibility = '1.7'

sourceCompatibility = '1.7'

to that submodule's build.gradle file.

当按照提示进行添加:

compileOptions {

sourceCompatibility JavaVersion.VERSION_1_7

targetCompatibility JavaVersion.VERSION_1_7

}

后,依然报这种错误,我又按照如下所示:

android {

defaultConfig {

multiDexEnabled true

}

}所示:进行修复问题。然而:问题依然没有解决解决方案:

后来经过反复查看,Libs下的jar是否重复,compile后来发现并不是重复问题,而是不支持带有common.io的其中一个依赖

对,没有错:问题就是它--》 org.apache.commons:commons-io:1.3.2 就是它出现MultiDexMerger

解决:将 implementation 'org.apache.commons:commons-io:1.3.2'

替换为: implementation('org.apache.commons:commons-io:1.3.2') {

exclude module:'commons-io'

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值