Error converting bytecode to dex: Cause: java.lang

2019-01-17 06:39发布

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 ?

14条回答
Root(大扎)
2楼-- · 2019-01-17 07:19

I ran into the same issue today and the problem was that in my Constants.java classed I have defined (by mistake)

public static final class Checkout {
.......
}

and

public static final class CHECKOUT {
......
}
查看更多
做个烂人
3楼-- · 2019-01-17 07:22

just do Build > Clean Project Wait for Cleaning Ends and then Build > Rebuild Project, and the error was gone. that's it.

查看更多
倾城 Initia
4楼-- · 2019-01-17 07:23

My solution was different, I was added these lines in proguard-rules.pro

-optimizationpasses 5
-overloadaggressively
-repackageclasses ''
-allowaccessmodification

Make sure to update everything from SDK manager as well.

查看更多
The star\"
5楼-- · 2019-01-17 07:23

Removing -overloadaggressively from my proguard-rules.pro fixed this for me.

Alternatively, adding -useuniqueclassmembernames also fixed it.

查看更多
看我几分像从前
6楼-- · 2019-01-17 07:24

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

查看更多
太酷不给撩
7楼-- · 2019-01-17 07:26

I tried ./gradlew clean build, Invalidating studio cache, restarting machine. But what solved the issue is turning Instant run off

查看更多
登录 后发表回答