23

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 ?

MBH
  • 16,271
  • 19
  • 99
  • 149

14 Answers14

82

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

Mahdi Astanei
  • 1,905
  • 1
  • 17
  • 30
47

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

phil
  • 825
  • 9
  • 13
  • actuallu i did 2 thing at the same tim, 1- i modified my proguard and added all possible option i found on internet, 2- i did change the package names as u suggested, im not sure which is the solution... thank you – MBH Mar 04 '16 at 16:49
  • 1
    Nice to hear that it worked for you. I also looked out for proguard errors. The solutions didn't solve the problem for me, but definitely also worth a try. – phil Mar 06 '16 at 22:07
  • Great find. I had an incorrect capital letter in the 'applicationId' variable in my projects build.gradle file. – running-codebase Mar 09 '17 at 03:25
10

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.

MOSDEV
  • 139
  • 4
  • preDexLibraries false helped, thanks! Android Studio 2.3.3 with buildToolsVersion 26.0.2 buided ok, but when trying to RUN gave and error – Pavel Biryukov Oct 13 '17 at 10:24
3

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.

Tassu
  • 37
  • 2
2

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.

Mohammed AlBanna
  • 2,350
  • 22
  • 25
2

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

xarlymg89
  • 2,552
  • 2
  • 27
  • 41
Milad Ahmadi
  • 1,019
  • 12
  • 19
1

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

Alternatively, adding -useuniqueclassmembernames also fixed it.

Josh Laird
  • 6,974
  • 7
  • 38
  • 69
1

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

Defuera
  • 5,356
  • 3
  • 32
  • 38
0

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.

Alexander M.
  • 3,308
  • 2
  • 20
  • 31
0

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

VahidHoseini
  • 495
  • 2
  • 10
  • 28
0

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 {
......
}
Zahid Rasheed
  • 1,536
  • 1
  • 10
  • 28
  • Please do not post the same answer to multiple questions. If the same information really answers both questions, then one question (usually the newer one) should be closed as a duplicate of the other. You can indicate this by [voting to close it as a duplicate](http://stackoverflow.com/help/privileges/close-questions) or, if you don't have enough reputation for that, [raise a flag](http://stackoverflow.com/help/privileges/flag-posts) to indicate that it's a duplicate. Otherwise, be sure you tailor your answer to *this* question and don't just paste the same answer in multiple places. – elixenide Dec 01 '16 at 15:17
  • Thanks for the information. I will take care of this in the future :) – Zahid Rasheed Dec 01 '16 at 15:19
0

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.

ruelluna
  • 787
  • 1
  • 11
  • 30
0

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

Mir Adnan
  • 844
  • 11
  • 24
-1

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.

Dovydas Šopa
  • 2,282
  • 8
  • 26
  • 34
shiny vn
  • 91
  • 3