37

I am moving my projects from eclipse to Android Studio. While running one of my app I get the following error. Not able to find any solution. I have enabled multidex as well.

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 1

also my gradle file is below

apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
    applicationId "com.myapp"
    minSdkVersion 9
    targetSdkVersion 21
    multiDexEnabled true
}buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard- android.txt'), 'proguard-project.txt', 'proguard-google-api-client.txt'
     }
   }
 }
 dependencies {
 compile 'com.android.support:support-v4:23.4.0'
 compile 'com.google.android.gms:play-services:+'
 compile 'com.google.http-client:google-http-client-gson:1.20.0'
compile 'com.google.code.gson:gson:2.1'
compile 'com.android.support:appcompat-v7:23.4.0'
compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/android-support-v7-cardview.jar')
compile files('libs/android-support-v7-recyclerview.jar')
compile files('libs/commons-logging-1.1.1.jar')
compile 'com.google.api-client:google-api-client:1.18.0-rc'
compile 'com.google.api-client:google-api-client-android:1.18.0-rc'
compile 'com.google.api-client:google-api-client-appengine:1.18.0-rc'
compile 'com.google.http-client:google-http-client:1.18.0-rc'
compile 'com.google.http-client:google-http-client-android:1.18.0-rc'
compile 'com.google.http-client:google-http-client-appengine:1.18.0-rc'
compile 'com.google.oauth-client:google-oauth-client:1.18.0-rc'
compile 'com.google.oauth-client:google-oauth-client-appengine:1.18.0-rc'
compile files('libs/google-api-client-gson-1.18.0-rc.jar')
compile files('libs/google-api-client-jackson2-1.18.0-rc.jar')
compile files('libs/google-api-client-java6-1.18.0-rc.jar')
compile files('libs/google-api-client-servlet-1.18.0-rc.jar')
compile files('libs/google-http-client-jackson2-1.18.0-rc.jar')
compile files('libs/google-http-client-jdo-1.18.0-rc.jar')
compile files('libs/google-oauth-client-java6-1.18.0-rc.jar')
compile files('libs/google-oauth-client-jetty-1.18.0-rc.jar')
compile files('libs/google-oauth-client-servlet-1.18.0-rc.jar')
compile files('libs/GraphView-4.0.1.jar')
compile files('libs/httpclient-4.0.1.jar')
compile files('libs/httpcore-4.0.1.jar')
compile files('libs/jackson-core-2.1.3.jar')
compile files('libs/jetty-6.1.26.jar')
compile files('libs/jetty-util-6.1.26.jar')
compile files('libs/jsr305-1.3.9.jar')
compile files('libs/jxl.jar')
compile files('libs/mail.jar')
compile files('libs/transaction-api-1.1.jar')
 }
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
user1938357
  • 1,466
  • 3
  • 20
  • 33
  • 1
    Possible duplicate of [Android java.exe finished with non-zero exit value 1](http://stackoverflow.com/questions/29045129/android-java-exe-finished-with-non-zero-exit-value-1) – Aditya Vyas-Lakhan May 28 '16 at 12:31
  • In the latest version 3.2 of AS, missing resource files may also cause this problem.I don't know if you have this problem.It only suggests that: aapt "finished with non-zero exit value 1 "and not explicit like other version. – user9965069 Jun 20 '18 at 03:02

17 Answers17

73

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 1

The upper error occure due to lot of reason. So I can put why this error occure and how to solve it.

REASON 1 : Duplicate of class file name

SOLUTION :

when your refactoring of some of your class files to a library project. and that time you write name of class file So, double check that you do not have any duplicate names

REASON 2 : When you have lot of cache Memory

SOLUTION :

Sometime if you have lot of cache memory then this error occure so solve it. go to File/Invalidate caches / Restart then select Invalidate and Restart it will clean your cache memory.

REASON 3 : When there is internal bug or used beta Version to Switch back to stable version.

SOLUTION :

Solution is just simple go to Build menu and click Clean Project and after cleaning click Rebuild Project.

REASON 4 : When you memory of the system Configuration is low.

SOLUTION :

open Task Manager and stop the other application which are not most used at that time so it will free the space and solve OutOfMemory.

REASON 5 : The problem is your method count has exceed from 65K.

SOLUTION :

open your Project build.gradle file add

defaultConfig {
        ...
        multiDexEnabled true
    }

and in dependencies add below line.

dependencies 
    {
       compile 'com.android.support:multidex:1.0.0'
    }
Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
11

**In my case problem solved with Instant Run DISABLE **enter image description here

Md. Ibrahim
  • 1,239
  • 14
  • 18
8

Check Whether multidex enabled or not in your build.gradle(app level) under dependencies.if not place like below

dependecies{
multidexEnabled true
}

Check your gradle.properties(app level).if you see the below code

#org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

remove # before the line ,then it should be like this

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
Trinadh Koya
  • 1,089
  • 15
  • 19
5

Please Add this into your gradle file

android {
...
defaultConfig {
    ...
    multiDexEnabled true
    }
}

AND also add the below dependency in your gradle

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

OR another option would be: In your manifest file add the MultiDexApplication package from the multidex support library in the application tag.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>
Naina
  • 99
  • 7
4

This can be because of following reason:

  1. one of the jar files inside project was using an older version of google play services.

  2. use multiDexEnabled true in defaultconfig

  3. Be specific with classes you add in dependencies. like

    compile 'com.google.android.gms:play-services-maps:8.4.0'

Not like compile 'com.google.android.gms:play-services:+'

Dipali Shah
  • 3,742
  • 32
  • 47
1

I tried everything but still this error won't go, until I changed my JDK version.

My JDK version was 7, and after I changed it to 8, the error went away, you can try it if nothing else works.

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
1

i have tried this one and it worked for me. hope it works for others too.

  1. Open build.gradle module file
  2. downgrade you sdkversion from 25 to 24 or 23
  3. add 'multiDexEnabled true'
  4. comment this line : compile 'com.android.support:appcompat-v7:25.1.0' (if it's in 'dependencies')
  5. Sync your project and ready to go.

Here i have attached screenshot to explain things. Go through this steps

happy to help.

thanks.

1

A temporary solution is to place the code below in the module build.gradle :

android { 
    aaptOptions.cruncherEnabled = false
    aaptOptions.useNewCruncher = false
}

And Sync the Project.

Mahesh Babariya
  • 4,560
  • 6
  • 39
  • 54
Mirza715
  • 420
  • 5
  • 15
1

Or you can try this -

Extend your Application class with MultiDexApplication instead of Application !
mayur saini
  • 209
  • 7
  • 17
1

Duplicate name Classes

like

class BackGroundTask extends AsyncTask<String, Void, Void> {

and

class BackgroundTask extends AsyncTask<String, Void, Void> {
Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
Karthik Kompelli
  • 2,104
  • 1
  • 19
  • 22
1

i have tried this one for more projects and it worked for me. note that solution can configure your app for multidex:

android {
     compileSdkVersion 25
     buildToolsVersion "25.0.1"

     defaultConfig {
           ...
           minSdkVersion 9
           targetSdkVersion 25
     }

     buildTypes {
          release {
              shrinkResources true
              minifyEnabled true
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
          }
     }}

 dependencies {
       compile 'com.android.support:support-v4:25.1.0'
       compile 'com.google.android.gms:play-services:8.3.0'
       ...
 }
medaou
  • 11
  • 2
1

Thank @Ironman for his complete answer, however I should add my solution according to what I've experienced facing this issue.

In build.gradle (Module: app):

compile 'com.android.support:multidex:1.0.1'

    ...

    dexOptions {
            javaMaxHeapSize "4g"
        }

    ...

    defaultConfig {
            multiDexEnabled true
    }

Also, put the following in gradle.properties file:

org.gradle.jvmargs=-Xmx4096m -XX\:MaxPermSize\=512m -XX\:+HeapDumpOnOutOfMemoryError -Dfile.encoding\=UTF-8

I should mention, these numbers are for my laptop config (MacBook Pro with 16 GB RAM) therefore please edit them as your config.

Shayan Amani
  • 5,787
  • 1
  • 39
  • 40
0

My Settings Screenshot: image

Thanks to this post.

Just turn off instant run in your settings. You can easily search the keyword "instant" like I showed and it would switch to the window you want.

Community
  • 1
  • 1
刘睿博
  • 11
  • 1
0

In my case I had 2 projects A and B. And I upgraded to gradle 4.5.

A was dependent on B but both had references of my 3rd party jar

I was getting this error

com.android.tools.r8.errors.CompilationError: Program type already present: com.mnox.webservice.globals.WebServiceLightErrorHashCode

Program type already present: com.mnox.webservice.globals.WebServiceLightErrorHashCode

To fix it

  1. I removed the duplicate jar's
  2. I used api in the B build.gradle file so that it gets referred to in A.

The other root cause can be if you have upgraded to gradle 4.5 and used implementation instead of api in your commons build.gradle

Siddharth
  • 9,349
  • 16
  • 86
  • 148
0

Just worth mentioning that while others suggest tempering with files, I was able to resolve this issue by installing a missing plugin (ionic framework)

Hopefully it helps someone.

cordova plugin add cordova-support-google-services --save

siege
  • 21
  • 1
  • 3
0

For me the solution was to delete the gradle cache folder (.gradle/caches) in the home directory and build again. Possibly due to a duplicate class loading issue.

html_programmer
  • 18,126
  • 18
  • 85
  • 158
0

For Ionic 4 Just

$ cordova clean

Helped me then run

$ ionic cordova run android --device
Code Spy
  • 9,626
  • 4
  • 66
  • 46