4

I have written a small code, but whenever I try to build the apk, I get the following error:

Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.multidex.ClassReferenceListBuilder with arguments {C:\Users\xxxx\Desktop\yyyyy\app\build\intermediates\multi-dex\debug\componentClasses.jar C:\Users\xxxx\Desktop\yyyyy\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar}

Where xxxx is my username, and yyyyy is project name. I have tried all possible solutions that I found on Stack Overflow, but I realized that all of them were asked about older versions.

I have the latest version of Android Studio. I am using latest version of Android SDK, the build tools, gradle, JDK 8.0 , and JRE 7. I also tried JRE 8.

build.gradle(module app) :
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
    applicationId "xxxx.yyyyy"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "Unreleased Demo Version"
    testInstrumentationRunner                 
"android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }

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

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
{
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.1'
}
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
Anuraag
  • 218
  • 3
  • 9

6 Answers6

0

In you build.gradle/app

defaultConfig {
    ....
   //Add this line
    multiDexEnabled true
}

dependencies {
   ....
   //Add this line
   compile 'com.android.support:multidex:1.0.0'
}
0

This happens as the Android platform has continued to grow, so has the size of Android apps. When your app and the libraries it references reach a certain size, you encounter build errors that indicate your app has reached a limit of the Android app build architecture

Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here: Source

android {
    defaultConfig {


        multiDexEnabled true
    }
}
Sathya Baman
  • 3,424
  • 7
  • 44
  • 77
  • I have tried all possible solution including this one.It doesn't helped me – Anuraag May 04 '17 at 04:11
  • After adding this go to FILE -> Invidate Cahes / restart – Sathya Baman May 04 '17 at 04:13
  • Tried, doesn't work. can you help me using Teamviewer – Anuraag May 04 '17 at 04:22
  • ok try removing compile 'com.android.support:multidex:1.0.1'. i updated the answer – Sathya Baman May 04 '17 at 04:24
  • Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.multidex.ClassReferenceListBuilder with arguments {C:\xxxx\yyyyy\Desktop\VoterSearch\app\build\intermediates\multi-dex\debug\componentClasses.jar C:\Users\xxxx\Desktop\yyyyy\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar} **After Your suggestion ** – Anuraag May 04 '17 at 04:27
  • Then check this.. http://stackoverflow.com/questions/33666261/android-studio-failed-to-run-command-java-xmx1024m-cp – Sathya Baman May 04 '17 at 04:44
0

Try this in Module:App gradle folder.

 multiDexEnabled true

        packagingOptions {
            exclude 'META-INF/DEPENDENCIES.txt'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/dependencies.txt'
            exclude 'META-INF/LGPL2.1'
        }
Pang
  • 9,564
  • 146
  • 81
  • 122
0

You have not shared any of your codes and dependencies you working with ,so it is difficult to guess exact problem.

but from error you posted ,i think your program cross the limit of 64K Methods.

Apk files conatins bytecode files in the form of DEX, and it has a limit of 65,536 methods in a single DEX file.

So if your App has more then 64k methods ,you should go for multiple Dex files.

Enabling mutiple Dex ,means app build process will generate more than one DEX file

defaultConfig {
....

multiDexEnabled true 
}

dependencies {
....

compile 'com.android.support:multidex:1.0.0'
}
Puneet Verma
  • 1,373
  • 2
  • 19
  • 23
0

I found there is no need to install JDK and JRE (ref:android studio 2.3.2 latest download page under system requirements)

And there is a folder named "jre" in programfiles/android-studio.

So I thought I shall uninstall JDK and JRE (as the problem related to java)

After this I reinstalled android studio.

And now it works fine. (I haven't done research in deep although it helped me)

Anuraag
  • 218
  • 3
  • 9
-1

This happen when your have cross 65,536 method reference limit.

Step 1

You can add the following to your app's build.gradle file

    android {
      defaultConfig {
      ...
      minSdkVersion 15 
      targetSdkVersion 25
      multiDexEnabled true
     }
  ...
}

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

Step 2A

After that you have to extend the Application class in the following way

public class MyApplication extends SomeOtherApplication {
  @Override
  protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
  }
}

Or you can do as below:

Step 2B

public class MyApplication extends MultiDexApplication { ... }

STEP 3

Finally update your manifest file like below

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.myapp">
   <application
        android:name="android.support.multidex.MultiDexApplication" >
    ...
   </application>
</manifest>
Farmaan Elahi
  • 1,620
  • 16
  • 18
  • Can you explain step 2 – Anuraag May 04 '17 at 04:37
  • There are two option provided in supoort library: First is that you can extend the normal Application class and on attachBaseContext method ,you can set MultiDex.install(this) Second is you can extend your application class from MultiDexApplication itself ,so that you dont need to setup anything on attachBaseContext method – Farmaan Elahi May 04 '17 at 04:41
  • Not working. Now it's showing Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. – Anuraag May 04 '17 at 04:51
  • Are you using 32 bit system or 64 bit? – Farmaan Elahi May 04 '17 at 04:53
  • Windows 7 32 bit – Anuraag May 04 '17 at 04:54
  • And the jvm version means 32 or 64? – Farmaan Elahi May 04 '17 at 04:59
  • jvm is also 32. What do you want to know exactly – Anuraag May 04 '17 at 05:03
  • Try setting the below code in your gradle.properties file and invalidate the cache by going to FILE -> Invidate Cahes / restart `org.gradle.jvmargs=-XX:MaxHeapSize\=2048m -Xmx2048m` – Farmaan Elahi May 04 '17 at 06:04
  • Error:Failed to complete Gradle execution. Cause: Unable to start the daemon process. This problem might be caused by incorrect configuration of the daemon. For example, an unrecognized jvm option is used. Please refer to the user guide chapter on the daemon at https://docs.gradle.org/3.5/userguide/gradle_daemon.html Please read the following process output to find out more: ----------------------- Error occurred during initialization of VM Could not reserve enough space for 2097152KB object heap – Anuraag May 04 '17 at 08:58