Error converting bytecode to dex: Cause: java.lang.RuntimeException: Exception parsing classes

转载请标明出处:http://blog.csdn.net/xx326664162/article/details/51859106 文章出自:薛瑄的博客

你也可以查看我的其他同类文章,也会让你有一定的收货!

问题:

在调试程序的时候,出现这个错误:

Error:Error converting bytecode to dex:
Cause: java.lang.RuntimeException: Exception parsing classes


Error:Execution failed for task ‘:artandroidclient:transformClassesWithDexForAviterichDebug’.
com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘C:\Program Files\Java\jdk1.8.0_66\bin\java.exe” finished with non-zero exit value 1

原因:

When i looked through the output of the gradle console

I scrolled close to the end of the exception. There is a part in that long exception line that actually mentions the cause:

AGPBI: { "kind":"error","text":"Error converting bytecode to dex: \n Cause: java.lang.RuntimeException: Exception parsing classes","sources":[{}],"original":"UNEXPECTED TOP-LEVEL EXCEPTION:\njava.lang.RuntimeException: Exception parsing classes\n\tat 
...
com.android.dx.command.Main.main(Main.java:106)\nCaused by: com.android.dx.cf.iface.ParseException: class name (cn/hdnc/ArtSDK/BuildConfig) does not match path (cn/hdnc/artsdk/BuildConfig.class)\n\tat 
...}
AGPBI: {"kind":"error","text":"1 error; aborting","sources":[{}]}

This way i found out where to search for missmatching package names/paths.

根本原因是:

app/build/source/BuildConfig/Build Varients/package name/BuildConfig中的package name项目中的包名不一致。

Error converting bytecode to dex: Cause: java.lang.RuntimeException: Exception parsing classes_第1张图片

解决方法:

我之所以会出现包名不一致,是因为手动修改包名,忘记修改 manifest.xml文件,下面提供两种修改包名的方法:

第一种:

手动修改包名需要修改两个地方:

  1. 项目中的包名
  2. manifest.xml文件中的 package=" "节点

第二种:

Error converting bytecode to dex: Cause: java.lang.RuntimeException: Exception parsing classes_第2张图片
图二

点击图二所示的图标,然后会出现2所示菜单,这个时候注意方框圈住的选项,默认是选中状态,我们把它取消,中间的空包名就会展开。

Error converting bytecode to dex: Cause: java.lang.RuntimeException: Exception parsing classes_第3张图片

我们就可以随意的修改包名了,选中想要修改的包名部分目录,Shift + F6 ,在弹出框选择Rename Package,稍等一会,可以看到包名已经发生了变化。OK,下图为我把包名test部分改为rename.

Error converting bytecode to dex: Cause: java.lang.RuntimeException: Exception parsing classes_第4张图片

参考:android studio如何修改包名

但是原作者没有理解一个知识点,参考我的这篇博客ApplicationId 与 PackageName的关系,

参考:Error converting bytecode to dex: Cause: java.lang.RuntimeException: Exception parsing classes - Android studio 2.0 beta 6

关注我的公众号,轻松了解和学习更多技术
这里写图片描述

你可能感兴趣的:(Android,Studio编译构建错误,Android,Studio编译或构建错误汇总)