将字节码转换为dex时出错:原因:java.lang.RuntimeException:解析类的异常 - Android Studio 2.0 beta 6 [英] Error converting bytecode to dex: Cause: java.lang.RuntimeException: Exception parsing classes - Android studio 2.0 beta 6

查看:688
本文介绍了将字节码转换为dex时出错:原因:java.lang.RuntimeException:解析类的异常 - Android Studio 2.0 beta 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用gradle更新到Android Studio 2.0 Beta 6的最新版本:

 依赖关系{
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
}

应用程序在模拟器和设备上运行得很好,我测试了每件事情,并且它工作正常。



只有在尝试生成签名APK时,我收到了很多错误,



我在依赖关系中遇到了一些错误,当我排除向量drawable,vector动画drawable和Support-v4库时,它们都解决了。

<现在我没有任何依赖关系错误。

现在我的应用程序模块的gradle.build看起来像这样:

  apply plugin:'com.android.application'

android {
configurations {
//all*.exclude group: 'com.android.support',module:'support-v4'
all * .exclude module:'animated-vector-drawable'
all * .exclude module:'support-v ector-drawable'
//all*.exclude模块:'support-v4'

}
存储库{
maven {urlhttps:// jitpack。 io}

}
compileSdkVersion 23
buildToolsVersion '23 .0.2'
defaultConfig {
applicationIdcom.test.test
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName1

// multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
productFlavors {
}

}

依赖项{
编译fileTree(dir:'libs',include:['* .jar' ])

compile('com.github.afollestad.material-dialogs:commons:0.8.5.5@aar'){
transitive = true
排除模块:'support-v4'
排除模块:'appcompat-v7'
排除模块:'recyclerview-v7'
}
编译'com.google.android.gms:play-services-ads:8.4.0'){
排除模块:'support-v4'
}
compile('com.google.android .gms:play-services-analytics:8.4.0'){
exclude module:'support-v4'
}
compile('com.android.support:appcompat-v7:23.2 $''$ {
排除模块:'support-v4'
排除模块:'动画矢量绘制'
排除模块:'support-vector-drawable'
}
compile('com.android.support:support-v4:23.2.0'){
排除模块:'animated-vector-drawable'
排除模块:'support-vector-drawable '
}
compile('com.android.support:palette-v7:23.2.0'){
排除模块:'support-v4'
}
compile('com.android.support:cardview-v7:23.2.0'){
排除模块:'support-v4'
}
compile('com.android .support:recyclerview-v7:23.2.0'){
排除模块:'support-v4'
}
compile('com.android.support:design:23.2.0') {
exclude module:'support-v4'
}
compile('com.nineoldandroids:library:2.4.0'){
排除模块:'support-v4'
}
compile('com.baoyz.swipemenulistview:library:1.2.1'){
排除模块:'support-v4'
排除模块:'appcompat-v7'
排除模块:'recyclerview-v7'
}
编译('com.squareup.picasso:picasso:2.5.2'){
排除模块:'support-v4'
}
compile('com.nononsenseapps:filepicker:2.5.0'){
排除模块:'support-v4'
排除模块:'appcompat-v7'
排除模块:'recyclerview-v7'

}
编译'com.google.code.gson:gson:2.6.1'
}


这些错误仅在我为发布版构建时显示: 这是错误当我打开multiDex时:

 错误:任务':app:transformClassesWithMultidexlistForRelease'的执行失败。 
> com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程'命令'/Library/Java/JavaVirtualMachines/jdk1.7.0_80。 jdk / Contents / Home / bin / java''以非零退出值结束1

是错误,当我把它关闭:

 :app:transformClassesWithDexForRelease 
错误:将字节码转换为dex时出错:
原因:java.lang.RuntimeException:解析类的异常

错误:任务':app:transformClassesWithDexForRelease'的执行失败。

> com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:java.util.concurrent.ExecutionException:com.android.ide.common.process.ProcessException:org.gradle.process。 internal.ExecException:进程'命令'/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/bin/java''以非零退出值1

我尝试将 buildToolsVersion '23 .0.2'更改为每个可能的版本,并且没有任何更改。



当我把版本22.0.1我得到这个错误:

 错误:将字节码转换为dex时出错:
原因:com.android.dx.cf.iface.ParseException:已添加的名称:string {a}

错误:执行失败对于任务':app:transformClassesWithDexForRelease'。
> com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:java.util.concurrent.ExecutionException:com.android.ide.common.process.ProcessException:org.gradle.process。 internal.ExecException:进程'命令'/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/bin/java''以非零退出值1

我尝试过所有可能的支持库版本和相同的结果。



和1.7并没有什么改变!



什么可以是其他可能的解决方案?

解决方案 div>

我也面临同样的错误,我正在通过重复的依赖关系或multidex等寻找现有的答案,但没有工作。 (Android studio 2.0 Beta 6,Build tools 23.0.2,没有multidex)

事实证明,我曾经使用过一个与软件包名称不匹配的软件包名称在其他ParseException行中,我发现我有不同模块中的文件,它们与可能与dexer冲突的类似软件包名称/路径相似。

例如:

.modulea.Interface.java



模块B: com.example.Xyz.ticketing.moduleb.Enumerations.java p>

模块C:依赖于A和B

将Xyz修改为小写后,dexer再次变好。



如何找出:



ParseExceptions 的gradle控制台,如下所示:



AGPBI:{kind:error,text :将字节码转换为dex时出错:\ nCause:java.lang.RuntimeException:解析类的异常



我滚动接近异常的结尾。实际上提到了原因的那部分长的异常行:



引起:com.android.dx.cf.iface.ParseException:类名(在/ dummycompany / mFGM / hata / hwp / BuildConfig)不匹配路径(在/ dummycompany / mfgm / hata / hwp / BuildConfig.class)

通过这种方式,我发现了在哪里搜索不匹配的包名称/路径


I updated to the last version of Android studio 2.0 Beta 6 with the gradle :

dependencies {
    classpath 'com.android.tools.build:gradle:2.0.0-beta6'
}

The app works perfectly fine on emulator and devices I tested every thing and it works fine.

I got many errors only when I try to Generate Signed APK,

I got some errors in dependencies, all of them solved when i excluded vector drawable, vector animate drawable and Support-v4 library

Now i dont have any dependencies error.

now my gradle.build for the app module looks like this:

apply plugin: 'com.android.application'

android {
    configurations {
        //all*.exclude group: 'com.android.support', module: 'support-v4'
        all*.exclude module: 'animated-vector-drawable'
        all*.exclude module: 'support-vector-drawable'
        //all*.exclude module: 'support-v4'

    }
    repositories {
        maven { url "https://jitpack.io" }

    }
    compileSdkVersion 23
    buildToolsVersion '23.0.2'
    defaultConfig {
        applicationId "com.test.test"
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1"

//        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile('com.github.afollestad.material-dialogs:commons:0.8.5.5@aar') {
        transitive = true
        exclude module: 'support-v4'
        exclude module: 'appcompat-v7'
        exclude module: 'recyclerview-v7'
    }
    compile('com.google.android.gms:play-services-ads:8.4.0') {
        exclude module: 'support-v4'
    }
    compile('com.google.android.gms:play-services-analytics:8.4.0') {
        exclude module: 'support-v4'
    }
    compile('com.android.support:appcompat-v7:23.2.0') {
        exclude module: 'support-v4'
        exclude module: 'animated-vector-drawable'
        exclude module: 'support-vector-drawable'
    }
    compile('com.android.support:support-v4:23.2.0') {
        exclude module: 'animated-vector-drawable'
        exclude module: 'support-vector-drawable'
    }
    compile('com.android.support:palette-v7:23.2.0') {
        exclude module: 'support-v4'
    }
    compile('com.android.support:cardview-v7:23.2.0') {
        exclude module: 'support-v4'
    }
    compile('com.android.support:recyclerview-v7:23.2.0') {
        exclude module: 'support-v4'
    }
    compile('com.android.support:design:23.2.0') {
        exclude module: 'support-v4'
    }
    compile('com.nineoldandroids:library:2.4.0') {
        exclude module: 'support-v4'
    }
    compile('com.baoyz.swipemenulistview:library:1.2.1') {
        exclude module: 'support-v4'
        exclude module: 'appcompat-v7'
        exclude module: 'recyclerview-v7'
    }
    compile('com.squareup.picasso:picasso:2.5.2') {
        exclude module: 'support-v4'
    }
    compile('com.nononsenseapps:filepicker:2.5.0') {
        exclude module: 'support-v4'
        exclude module: 'appcompat-v7'
        exclude module: 'recyclerview-v7'

    }
    compile 'com.google.code.gson:gson:2.6.1'
}

The errors shows up only when I build for release:

This is the error when i turn on multiDex:

Error:Execution failed for task ':app:transformClassesWithMultidexlistForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

And this is the error when i turn it off:

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

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

> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

I tried to change the buildToolsVersion '23.0.2' to every possible version and nothing changed.

when i put the version 22.0.1 i got this error:

Error:Error converting bytecode to dex:
Cause: com.android.dx.cf.iface.ParseException: name already added: string{"a"}

Error:Execution failed for task ':app:transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

I tried with all possible support libraries version and same result.

I tried with Java 1.6 and 1.7 and nothing has changed !

what can be other possible solution please ?

解决方案

I also faced the same error, and i was searching through many existing answers with duplicate dependencies or multidex etc. but none worked. (Android studio 2.0 Beta 6, Build tools 23.0.2, no multidex)

It turned out that i once used a package names which didn't match the package name that is depicted in the Manifest.

In other ParseException lines, i found out that i had files in different modules whith similiar package names/paths that possibly conflicted the dexer.

Example:

Module A: com.example.xyz.ticketing.modulea.Interface.java

Module B: com.example.Xyz.ticketing.moduleb.Enumerations.java

Module C: Has dependencies on A and B

After fixing "Xyz" to lowercase, the dexer was fine again.

How to find out:

When i looked through the output of the gradle console for the ParseExceptions that looks like this:

AGPBI: {"kind":"error","text":"Error converting bytecode to dex:\nCause: java.lang.RuntimeException: Exception parsing classes"

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

Caused by: com.android.dx.cf.iface.ParseException: class name (at/dummycompany/mFGM/hata/hwp/BuildConfig) does not match path (at/dummycompany/mfgm/hata/hwp/BuildConfig.class)

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

这篇关于将字节码转换为dex时出错:原因:java.lang.RuntimeException:解析类的异常 - Android Studio 2.0 beta 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆