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

MBH*_*MBH 23 android gradle build.gradle android-gradle-plugin

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

dependencies {
    classpath 'com.android.tools.build:gradle:2.0.0-beta6'
}
Run Code Online (Sandbox Code Playgroud)

该应用程序在模拟器和设备上运行完美,我测试了所有东西,它工作正常.

只有当我尝试生成签名APK时,我才会收到很多错误,

我在依赖项中遇到了一些错误,当我排除了矢量drawable,vector animate drawable和Support-v4库时,所有这些都解决了

现在我没有任何依赖性错误.

现在我的app模块的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-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'
}
Run Code Online (Sandbox Code Playgroud)

只有在我为发布版本构建时才会显示错误:

这是我打开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
Run Code Online (Sandbox Code Playgroud)

当我将其关闭时,这是错误:

: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
Run Code Online (Sandbox Code Playgroud)

我试图改变buildToolsVersion '23.0.2'到每个可能的版本,没有任何改变.

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

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
Run Code Online (Sandbox Code Playgroud)

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

我试过Java 1.6和1.7,没有任何改变!

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

Mah*_*nei 83

只是Build > Clean Project 等待清洁结束然后Build > Rebuild Project,错误消失了.而已.

  • 我有相同的错误消息,这有助于我解决问题.谢谢.我的清单中肯定有正确的包装. (2认同)
  • 帮助了我.这是一些文件名在某些系统上不区分大小写的问题 (2认同)
  • 帮了我三个!;) (2认同)

phi*_*hil 47

我也面临同样的错误,我正在搜索许多现有的答案与重复的依赖关系或multidex等,但没有工作.(Android studio 2.0 Beta 6,构建工具23.0.2,没有multidex)

原来,我曾经使用的包名称与Manifest中描述的包名称不匹配.

在其他ParseException行中,我发现我有不同模块中的文件,其中包含可能与dexer冲突的类似包名/路径.

例:

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

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

模块C:依赖于A和B.

将"Xyz"固定为小写后,dexer再次正常.

如何找出:

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

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

我滚动接近异常的结尾.该长期异常行中有一部分实际上提到了原因:

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

这样我就找到了搜索不匹配包名/路径的位置


MOS*_*DEV 10

我的解决方案是修改Build Gradle文件.我发现,问题是GC开销(内存不足).

所以我在配置中添加了一些代码

android {
  dexOptions {
    incremental = true;
    preDexLibraries = false
    javaMaxHeapSize "2g"
  } 
}
Run Code Online (Sandbox Code Playgroud)

proguard还有一些其他问题.您还要将minifyEnabled设置为false.