将字节码转换为 dex 时出错:原因:java.lang.RuntimeException:异常解析类 - Androi

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

问题描述

我用 gradle 更新到了最新版本的 Android studio 2.0 Beta 6:

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.

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

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

我在依赖项中遇到了一些错误,当我排除矢量绘图、矢量动画绘图和 Support-v4 库时,所有这些错误都解决了

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.

现在我的 app 模块的 gradle.build 看起来像这样:

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:

这是我打开multiDex时的错误:

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

我尝试将 buildToolsVersion '23.0.2' 更改为所有可能的版本,但没有任何改变.

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

当我输入 22.0.1 版本时出现此错误:

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.

我尝试使用 Java 1.6 和 1.7,但没有任何改变!

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

请问还有什么其他可能的解决方案?

what can be other possible solution please ?

推荐答案

我也遇到了同样的错误,我正在搜索许多具有重复依赖项或 multidex 等的现有答案,但没有一个有效.(Android studio 2.0 Beta 6,构建工具 23.0.2,无 multidex)

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.

在其他 ParseException 行中,我发现我在不同模块中有文件,这些文件具有相似的包名称/路径,可能会与 dexer 发生冲突.

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

示例:

模块 A:com.example.xyz.ticketing.modulea.Interface.java

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

模块 C:依赖于 A 和 B

Module C: Has dependencies on A and B

将Xyz"修复为小写后,dexer 又正常了.

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

如何找出:

当我查看 gradle 控制台的输出时,ParseExceptions 看起来像这样:

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

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

AGPBI: {"kind":"error","text":"Error converting bytecode to dex: Cause: 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:

引起:com.android.dx.cf.iface.ParseException:类名(at/dummycompany/mFGM/hata/hwp/BuildConfig)与路径不匹配(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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:Android Gradle 实现与 CompileOnly 性能 下一篇:Android Gradle 找不到符号类 Gson

相关文章

最新文章