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

佐手、 提交于 2019-11-28 06:22:51

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

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

The solution for me is to modifing the Build Gradle file. I found out, that the problem is a GC overhead (out of memory).

So I add some code to my configuration

android {
  dexOptions {
    incremental = true;
    preDexLibraries = false
    javaMaxHeapSize "2g"
  } 
}

There is some other problem with proguard. You've to set minifyEnabled to false also.

I had a wrong package name in one of the helper class,hence I was having the error.So check all the Classes and make sure you have correct package name.

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.

MiladAhmadi

If your targetSdkVersion is 25 or higher version and you use JDK 8 you have to add in your build.gradle file the following:

android {
   compileSdkVersion 26
   buildToolsVersion "26.0.0"

    defaultConfig {
        ...        
        jackOptions {
            enabled true
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

More info: https://stackoverflow.com/a/37294741

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

Alternatively, adding -useuniqueclassmembernames also fixed it.

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

Got this issue while using the Android studio template for Login activity.
I've selected "activity" package to put my activity into.
The template in AndroidManifest.xml, instead of .activity.LoginActivity used the .LoginActivity thus causing the error.

If you faced this error, certainly your package in manifest differ from the others that you have set in your classes. be careful.

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 {
......
}

In my case, there was a class that I made that I didn't use yet. So I have to delete the class or use the class.

I faced the same error. Appears that its due to renaming a package to lower case and a class had the previous case wording.

shiny vn

Your gradle.build file will contain

compile files('libs/httpclient-4.2.1.jar')

compile 'org.apache.httpcomponents:httpclient:4.5'

compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'

By removing this line from file.

compile files('libs/httpclient-4.2.1.jar') 

It will work fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!