错误Multiple dex files define Lcom/android/tools/fd/runtime/MonkeyPatcher的解决

错误Multiple dex files define Lcom/android/tools/fd/runtime/MonkeyPatcher的解决

在Gradle Console中看到了很多红色的warnning和构建错误提示.

:app:transformClassesWithDexForTencentDebug
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(com.squareup.haha.guava.base.Joiner$1) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(com.squareup.haha.guava.collect.Iterables$2) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(com.squareup.haha.guava.collect.Iterables$3) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithDexForTencentDebug'.
> 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/android/tools/fd/runtime/MonkeyPatcher;

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

其中关键的信息来自Multiple dex files define Lcom/android/tools/fd/runtime/MonkeyPatcher
于是找了很多文章, 其中提到这个MonkeyPatcher关键字的文章都是关于’Instant Run’的.

InstantRun 原理——深度剖析 AndroidStudio 2.0

看来是Instant Run的问题了. 把Instant Run关闭就好了.
具体位置在File -- Setting -- Build,Execution,Deployment --Instant Run

关闭之后构建成功. That’s all.

错误通常是因为引入的库文件中包含了相同的类而导致的。解决该问题的方法如下: 1.检查并删除重复的库文件 在你的项目的app目录下,打开build.gradle文件,查找dependencies节点,检查是否引入了重复的库文件,如果有重复的库文件,则删除其中一个即可。 2.使用exclude排除重复的库文件 如果你的项目中需要同时引用两个库文件,而这两个库文件中都包含了相同的类,那么可以使用exclude命令来排除其中一个库文件中的冲突类。具体操作如下: ``` dependencies { implementation ('com.library1:library1:1.0.0') { exclude group: 'com.alibaba', module: 'fastjson' } implementation 'com.library2:library2:1.0.0' } ``` 上面的代码中,我们在引入library1库文件时使用了exclude命令来排除了其中的fastjson类,这样就可以避免与library2库文件中的fastjson类冲突了。 3.使用不同版本的库文件 如果你的项目中引入的两个库文件中都包含了相同的类,但是它们的版本不同,那么可以尝试使用不同版本的库文件来解决冲突。具体操作如下: ``` dependencies { implementation 'com.library1:library1:1.0.0' implementation 'com.library2:library2:2.0.0' } ``` 上面的代码中,我们分别引入了library1和library2两个库文件,它们的版本分别为1.0.0和2.0.0,这样就可以避免它们之间的冲突了。 总之,解决该问题的关键是要找到引起冲突的库文件,并采取相应的措施进行解决
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值