Android- Error:Execution failed for task ':app:transformClassesWithDexForRelease'
Asked Answered
Q

40

201

The Problem is that i am able to run my app when i change to debug mode but it fails when i switch to release mode.

Exception:

**FAILURE: Build failed with an exception.**
> 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.8.0_65.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

When i ran the gradle build command with stacktrace then this is what i get

./gradlew app:transformClassesWithDexForRelease --stacktrace

> 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.8.0_73.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

*Exception is:*

>org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithDexForRelease'.
            at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
            at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
            at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
            at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
            at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
            at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
            at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
            at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
            at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
            at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
            at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
            at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
            at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
            at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:25)
            at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:110)
            at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
            at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
            at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
            at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
            at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
            at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
            at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
            at org.gradle.initialization.DefaultGradleLauncher$4.run(DefaultGradleLauncher.java:154)
            at org.gradle.internal.Factories$1.create(Factories.java:22)
            at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
            at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:52)
            at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:151)
            at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:32)
            at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:99)
            at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:93)
            at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
            at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62)
            at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:93)
            at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:82)
            at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:94)
            at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
            at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
            at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:43)
            at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
            at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:78)
            at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:48)
            at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:52)
            at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
            at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
            at org.gradle.util.Swapper.swap(Swapper.java:38)
            at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.health.DaemonHealthTracker.execute(DaemonHealthTracker.java:47)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:66)
            at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
            at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.health.HintGCAfterBuild.execute(HintGCAfterBuild.java:41)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
            at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
            at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
            at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
    Caused by: java.lang.RuntimeException: 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.8.0_73.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
            at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:54)
            at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:57)
            at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:47)
            at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:173)
            at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
            at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:244)
            at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:220)
            at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:231)
            at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:209)
            at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
            at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
            ... 68 more
    Caused by: 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.8.0_73.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
            at com.android.build.gradle.internal.transforms.DexTransform.transform(DexTransform.java:422)
            at com.android.build.gradle.internal.pipeline.TransformTask$3.call(TransformTask.java:178)
            at com.android.build.gradle.internal.pipeline.TransformTask$3.call(TransformTask.java:174)
            at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:55)
            ... 77 more
    Caused by: 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.8.0_73.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
            at com.android.builder.core.AndroidBuilder.runDexer(AndroidBuilder.java:1472)
            at com.android.builder.core.AndroidBuilder.convertByteCode(AndroidBuilder.java:1389)
            at com.android.build.gradle.internal.transforms.DexTransform.transform(DexTransform.java:250)
            ... 80 more
    Caused by: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
            at com.android.builder.core.AndroidBuilder.runDexer(AndroidBuilder.java:1456)
            ... 82 more
    Caused by: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
            at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:43)
            at com.android.builder.core.AndroidBuilder$2.call(AndroidBuilder.java:1464)
            at com.android.builder.core.AndroidBuilder$2.call(AndroidBuilder.java:1456)
    Caused by: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
            at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:367)
            at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:41)
            ... 2 more

I am using

  • Android Studio 2.0 Beta 6
  • Java version: Java(TM) SE Runtime Environment (build 1.8.0_73-b02)
  • Gradle Version: com.android.tools.build:gradle:2.0.0-beta6
  • And i have Multidex enabled

My build.gradle file

apply plugin: 'com.android.application'
apply plugin: 'com.getkeepsafe.dexcount'

android {

    def VERSION_CODE = 52
    def VERSION_NAME = "1.0"
    compileSdkVersion 23
    buildToolsVersion '23.0.2'

    defaultConfig {
        applicationId "com.example.app"
        manifestPlaceholders = [appName: "Personal App"]
        minSdkVersion 14
        targetSdkVersion 23
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
        versionCode VERSION_CODE
        versionName VERSION_NAME

        // Enabling multidex support.
        multiDexEnabled true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
        encoding = 'UTF-8'
    }

    signingConfigs {
        livekeystore {
            storeFile file('../key.jks')
            keyAlias 'livekeystore'
            keyPassword '123asd'
            storePassword '123asd'
        }
    }


    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            zipAlignEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            signingConfig signingConfigs.burgerking

            manifestPlaceholders = [googleMapsKey: "@string/release_google_map_key", appNameSuffix: ""]
        }

        debug {
            applicationIdSuffix '.dev'
            debuggable true
            minifyEnabled false
            shrinkResources false
            zipAlignEnabled false

            manifestPlaceholders = [googleMapsKey: "@string/debug_google_map_key", appNameSuffix: ' (Dev-' + VERSION_CODE + ')']

        }
    }

    dexOptions {
        incremental true
        javaMaxHeapSize "4g" // 2g should be also OK
    }

    useLibrary 'org.apache.http.legacy'

}

repositories {
    maven { url 'https://mint.splunk.com/gradle/' }
    maven { url "http://dl.bintray.com/populov/maven" }
    mavenCentral()
}

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.4.2'
        classpath 'com.newrelic.agent.android:agent-gradle-plugin:4.244.0'
    }
}


dependencies {
    compile 'com.google.code.gson:gson:2.4'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.android.support:recyclerview-v7:23.2.0'
    compile 'com.android.support:cardview-v7:23.2.0'
    compile 'com.android.support:design:23.2.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.google.android.gms:play-services-base:8.4.0'
    compile 'com.google.android.gms:play-services-location:8.4.0'
    compile 'com.google.android.gms:play-services-analytics:8.4.0'
    compile 'com.google.android.gms:play-services-maps:8.4.0'
    compile 'com.google.android.gms:play-services-ads:8.4.0'
    compile 'com.googlecode.libphonenumber:libphonenumber:7.0.5'
    compile 'com.facebook.android:facebook-android-sdk:4.1.1'
    compile 'de.greenrobot:eventbus:2.4.0'
    compile 'com.viewpagerindicator:library:2.4.1@aar'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.squareup:pollexor:2.0.2'
    compile 'com.makeramen:roundedimageview:2.1.0'
    compile 'com.mcxiaoke.volley:library:1.0.16@aar'
    compile files('libs/now-auth-api.jar')
    compile 'com.jakewharton:butterknife:5.1.2'
    compile 'com.github.ksoichiro:android-observablescrollview:1.2.0'
    compile 'io.card:android-sdk:5.3.0'
    compile 'com.appboy:android-sdk-ui:1.10.3'
    testCompile 'junit:junit:4.11'
    testCompile('org.mockito:mockito-core:1.9.5') {
        exclude group: 'org.hamcrest'
    }
    testCompile('org.powermock:powermock-module-junit4:1.5') {
        exclude group: 'org.hamcrest'
    }
    testCompile('org.powermock:powermock-api-mockito:1.6.2') {
        exclude group: 'org.hamcrest'
    }

    compile 'me.grantland:autofittextview:0.2.1'

}

It seems i am able to get my release build working if i remove minifyEnabled true from it. Why is that, is there another way to solve it

Queridas answered 9/3, 2016 at 11:25 Comment(8)
could you post your app's build.gradle file?Pellet
@Pellet i have updated the question, Please take a look at it nowQueridas
Yes @Sheraz you are right that switching minifyEnabled to false solves the issue. I read this in doc : 'you have to enable minifyEnabled in order to turn on code shrinking, and then shrinkResources to turn on resource shrinking. If you have not already been using minifyEnabled, make sure you get that working before also adding shrinkResources, since you may have to edit your proguard-rules.pro file to make sure any methods you access with reflection etc are listed as keep rules in that file' (tools.android.com/tech-docs/new-build-system/resource-shrinking). See if this is the case.Pellet
@Pellet it still doesnt solve the problem if i run the task with debug then i get this error Uncaught translation error: com.android.dx.cf.code.SimException: com.android.dx.rop.cst.CstMethodRef cannot be cast to com.android.dx.rop.cst.CstInterfaceMethodRef Queridas
I have the same problem with my project. If I use the com.android.tools.build:gradle:1.3.0, I'm able to compile. As soon as I use the 2.0.0 it gives me the same problemDecarbonate
I had the same issue because my project has duplicated libraries, external classes which are duplicate classes from android framework. For example I had QName.class (and other too) in library xpp3_min-1.1.4c which are duplicate class from android-26 library. To avoid this issue please follow the link: #30648672Cosher
minifyEnable true gives me exception - Below is my Question, #51720518 Please help me with this.Deactivate
got same problem and I just rm -rf .gradle and it worksExhibitionism
Q
46

For me, the problem was solved after I removed jar file from my project. it seems that one of the jar files inside my project was using an older version of google play services.

Queridas answered 9/3, 2016 at 18:5 Comment(6)
same issue with jackrabbit-standalone-2.12.2.jar. If I add it to project then the issue raises.Hinge
@MikeOx I updated some Android tools, and as a result I ended up with two versions of a few jar files, e.g. mockable-android-24.jar and mockable-android-25.jar. Removing the older ones fixed these build errors for me.Crossbill
but i am not using any jar file then why i am facing this problemDemonstrator
Can you please provide more details explanation for this solutionClipper
@IvanMilisavljevic You can use Gradle now, not JAR files. developers.google.com/android/guides/setup#splitErl
Thanks a lot. Never would have taught of this.Sampling
B
193

i fixed it just this code.

local.properties

org.gradle.jvmargs=-XX\:MaxHeapSize\=512m -Xmx512m

and you should do this changing on gradle

defaultConfig {
    applicationId "yourProjectPackage"
    minSdkVersion 15
    versionCode 1
    versionName "1.0"
    targetSdkVersion 23

    multiDexEnabled true //important
}
Backandforth answered 21/7, 2016 at 12:6 Comment(6)
"local.properties" is that a file name or a configuration value? Where (eg: in which folder) is it located inside the project?Iniquity
The local.properties file goes in the project's root level. if you have a problem about multiDex--> developer.android.com/studio/build/multidex.htmlBackandforth
I just inserted multiDexEnabled true in my build.gradle and the magic was done. Thank you.Vesuvian
I don't know what all of this means, but it worked for me!Hydrous
On API <21, multiDexEnabled without extending Application class from MultiDexApplication will lead to NoClassDefFoundErrors.Heinie
org.gradle.jvmargs=-XX\:MaxHeapSize\=512m -Xmx512m fixed for me, thanks!Uela
R
85

If you make multiDexEnabled = true in defaultConfig of the app, you will get the desired result.

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 22
    multiDexEnabled = true
}
Roney answered 3/9, 2016 at 14:50 Comment(1)
That is not the only step to allowing Multidex. And you only need it when you see a DexException, anyway. developer.android.com/studio/build/multidex.htmlErl
Q
46

For me, the problem was solved after I removed jar file from my project. it seems that one of the jar files inside my project was using an older version of google play services.

Queridas answered 9/3, 2016 at 18:5 Comment(6)
same issue with jackrabbit-standalone-2.12.2.jar. If I add it to project then the issue raises.Hinge
@MikeOx I updated some Android tools, and as a result I ended up with two versions of a few jar files, e.g. mockable-android-24.jar and mockable-android-25.jar. Removing the older ones fixed these build errors for me.Crossbill
but i am not using any jar file then why i am facing this problemDemonstrator
Can you please provide more details explanation for this solutionClipper
@IvanMilisavljevic You can use Gradle now, not JAR files. developers.google.com/android/guides/setup#splitErl
Thanks a lot. Never would have taught of this.Sampling
B
39

I did receive also the same error:

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.8.0_60\bin\java.exe'' finished with non-zero exit value 1

well I fixed this with help of following steps:

  1. Open your app's build.gradle (not the one in the project root) and add:

    android {
    //snippet
    //add this into your existing 'android' block
    
        dexOptions {
        javaMaxHeapSize "4g"
        }
    
    //snip
    }
    
  2. Try your build again.

Note: 4g is 4 Gigabytes and this is a maximum heap size for dex operation.

Billie answered 1/12, 2016 at 7:24 Comment(2)
Saved my day! Cheers!Barocchio
The best...I've been roaming around for hours..thanks!Ravo
A
35

NO NEED FOR MULTIDEX, I REPEAT, NO NEEED FOR MULTIDEX


Let me elaborate: Multidex is basically a tool that comes with Android, and if you set it to true, apps with >64,000 methods are able to compile using a slightly altered build process. However you only need to use multidex if your error looks like this:

trouble writing output: Too many field references: 131000; max is 65536. You may try using --multi-dex option.

or like this

Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536

But that is not the case here! The problem here (for me atleast) is being caused by your build.gradle file's dependencies.

THE SOLUTION: Utilize specific dependencies—don't just import an entire section of dependencies!

For example, if you need the Play Services dependency for location, only import it for location.

DO:

compile 'com.google.android.gms:play-services-location:11.0.4'

DON'T:

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

Another issue that could be causing this may be some sort of external library you are using, that is referencing a prior version of your dependency. Follow these steps in that case:

  1. Go to SDK manager, and install any updates to your dependencies
  2. Make sure that your build.gradle file shows the latest version. To get the latest version, use this link: https://developers.google.com/android/guides/setup
  3. Edit your library (or install an updated version if that exists), to reference the latest version

I know this question is old, but I need to get this answer out there, because using multidex for no reason could potentially cause ANR's for your app! ONLY use multidex if you're sure you need it, and you understand what it is.

I myself spent hours trying to resolve this issue without multidex, and I just wanted to share my findings—hope this helps

Anagrammatize answered 11/8, 2017 at 17:18 Comment(5)
Brilliant! Works perfectly!Bluff
How do you know which specific dependency causes the problem? I have added com.facebook.android:audience-network-sdk:4.+ and I cannot build since then.Ginseng
You saved my day!Hedonic
such a stupid answer. if you have a lot of dependencies you will need multi dex anyway. just add kotlin libraries, a couple of google services (com.google.android.gms:play-services-*:*) , firebase services, crashlytics, gson, androidx (support libraries), cardview, recyclerview, android.material:material. IT'S NOT POSSIBLE WITHOUT MULTI DEX (do you like capslock? I don't, so please don't answer such questions here next time...)Underthrust
Some body is clever here! Exactly !, its not multidex error, multidex error is different, and it can be from some of dependencies. and @user155, RUCHIR IS NOT RESPONSIBLE FOR YOUR DEPENDENCIES PROBLEM!and i like capslocks :)Alisaalisan
P
26

Add multiDexEnabled true in your defaultConfig in the app level gradle.

defaultConfig {
    applicationId "your application id"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
Perturb answered 18/4, 2017 at 8:41 Comment(0)
G
24

I had the similar problem in my app. Here is what I did.

1.add this for build.gradle in module: app

multiDexEnabled = true

So the code would be like:

    android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example..."
        minSdkVersion 17
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        multiDexEnabled = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

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

This worked for me. Hope this helps you too :)

In the same project I was using Firebase too. So enabling multiDexEnabled let to another problem in Firebase for Pre Lollipop devices. Some FireBase classes were not identified. (Unable to get provider com.google.firebase.provider).
Method to resolve that is explained here.

Gambrill answered 14/3, 2017 at 13:26 Comment(1)
minifyEnable true gives me exception - Below is my Question, #51720518 Please help me with this.Deactivate
C
21

I got this error When upgrading Google play services to 9.0 from 7.5

Having error with below one:

compile 'com.google.android.gms:play-services:9.0.0'

When I changed to

compile 'com.google.android.gms:play-services:7.5.0'

There is no error. Try this

Chump answered 23/7, 2016 at 22:17 Comment(4)
thanks i have changed the version to compile 'com.google.android.gms:play-services:8.4.0' i think volley uses some old Google play services which are not compatible with play-services:>9.0Oratorical
This was the solution for me. The problem is that several third-party modules reference play-services with different versions so how is it expected that these versions are going to be in sync all the time? Very weird architectural detail.Huntlee
Your should not use this. Please selectively compile those libraries. developers.google.com/android/guides/setup#splitErl
where to change ....above changes ? can you please tell me the file name ?Tanika
J
14

After updating to Android 3.4, I started to get the error, tried all the above solutions.

Root cause of the problem was, updating Android Studio enabled the Instant Run.

Hence, one of the solutions you can try is Disabling Instant Run, if its enabled for you, fixed my problem.

Jugglery answered 22/4, 2019 at 7:14 Comment(6)
I had the same issue. Disabling Instant Run and enabling it again worked for me.Bellabelladonna
Fixed my issue too. Mind you - Instant Run is useful so I hope there's a better fix soonSoidisant
Yes absolutely its useful! Hope there is a fix soon! @SimonHJugglery
Aaaaarg they always enable this on the update and it always causes so many issues.Autotrophic
Jep, this was the cause of the problem for me too after putting Firebase in the project, disabling Instant Run finally lets me build it, thanks!Schnell
Disabling Instant run worked for me with this issue. Didn't get the error again.Jonathonjonati
A
12

Well, I believe the question is answered and has already been accepted. But I am going to write what I faced and how I solved it.

I did receive also the same error:

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.8.0_60\bin\java.exe'' finished with non-zero exit value 1

I wasn't fortunate to apply all the settings and got success. But when I tried to Debug the project again. This time I got Three Error (including above):

Error:Java HotSpot(TM) 64-Bit Server VM warning: CodeCache is full. Compiler has been disabled.

and

Error:Java HotSpot(TM) 64-Bit Server VM warning: Try increasing the code cache size using -XX:ReservedCodeCacheSize=

So what I did? I just go to Android Studio:

File > Invalidate Caches / Restart.. > Invalidate & Restart

Quick Fix!

Extra Note:

What I found in Gradle Console:

:app:incrementalDebugTasks :app:prePackageMarkerForDebug :app:fastDeployDebugExtractor :app:generateDebugInstantRunAppInfo :app:transformClassesWithDexForDebug To run dex in process, the Gradle daemon needs a larger heap. It currently has approximately 910 MB. For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB. To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties. For more information see https://docs.gradle.org/current/userguide/build_environment.html :app:transformClassesWithDexForDebug FAILED

Read More about it Here on Oracle Blog

Apophasis answered 16/8, 2016 at 11:1 Comment(0)
A
9

I have just written this code into gradle.properties and it is ok now

org.gradle.jvmargs=-XX:MaxHeapSize\=2048m -Xmx2048m
Averi answered 27/9, 2016 at 8:19 Comment(0)
A
8
  1. Remove the jar files in your gradle
  2. Sync it
  3. Copy that jar and sync it

This worked for me.

Anthropologist answered 24/7, 2016 at 15:56 Comment(2)
Can you be more specific which jar files? Is it the jar files inside our project gradle/wrapper?Affer
Don't know what it is with people mentioning "the jars". That doesn't explain anything.Chatty
D
7

It worked to me only using a specific service.

For example instead of use:

compile 'com.google.android.gms:play-services:10.0.1'

I used:

com.google.android.gms:play-services-places:10.0.1

Dianthe answered 28/12, 2016 at 22:46 Comment(1)
Same here. I solved the problem by replacing compile 'com.google.android.gms:play-services:10.2.0' with compile 'com.google.android.gms:play-services-location:10.2.0'Thuthucydides
P
7

Sol 1: In build.gradle:

defaultConfig {
    multiDexEnabled true
}

Clean your project and rebuild.

Sol 2: in local.properties add,

org.gradle.jvmargs=-XX\:MaxHeapSize\=512m -Xmx512m

Sol 3

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

Else add all 3 in your application.

Promycelium answered 13/9, 2017 at 13:13 Comment(0)
I
6

I know it's a bit of an old question, but still. Everytime this happens to me, it's because I've included all of the play-services libraries. Just change play-services:x.x.x to play-service-:x.x.x in the build.gradle(module) file

Imperil answered 29/7, 2016 at 0:25 Comment(0)
E
5

just setting the multiDexEnabled to true worked fine.

    defaultConfig 
    {
        multiDexEnabled true     
    }
Excitor answered 14/3, 2017 at 19:58 Comment(0)
M
3

I've updated jdk to 1.8.0_74, Android-studio to 2.1 preview 1 and add to Application file

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}
Menfolk answered 9/3, 2016 at 16:13 Comment(0)
T
3

I had the same problem. One day the program was working perfectly, and the following wasn't. I checked on Github the changes I made. For me the problem was on build.gradle (Module:app) in the dependencies:

compile 'com.android.tools.build:gradle:2.1.2'

This line was the one that was causing the problem. After changing it the app was running properly again

Terri answered 11/8, 2016 at 9:54 Comment(3)
Not Working Any Other chance>Preheat
Changing it to what?Anagrammatize
I erased it (I was checking it now) and it kept workingTerri
A
2

add this line in your build.gradle

 defaultConfig {
    ............
    aaptOptions.cruncherEnabled = false
    aaptOptions.useNewCruncher = false
    compileOptions.encoding = 'ISO-8859-1'
    multiDexEnabled true
}
Abroad answered 3/2, 2017 at 12:0 Comment(1)
Which "line" did you add here?Erl
M
2

In DefaultConfig Add multiDexEnabled = true

    defaultConfig {
    applicationId "com.test"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    multiDexEnabled = true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Machuca answered 12/4, 2017 at 6:11 Comment(0)
J
2

So, mine didn't get resolved by adding the multiDexEnabled flag. It actually was there before getting the error message.

What resolved the error for me was making sure I was using the same version of all play-services libraries. In one library I had 11.8.0 but in the app that consumes the library I was using 11.6.0 and that difference was what caused the error message.

So, instead of changing your libraries to a specific version like previous answers, maybe you wanna check you're using the same version all across since mixing versions is explicitly discouraged by Android Studio by warnings.

Julide answered 15/2, 2018 at 21:22 Comment(0)
A
2

After lots of effort I just added below credential and I succeed

1) app-> 'proguard-rules.pro' file

-ignorewarnings

-keep class * {
    public private *;
}

2) And also added in app -> build.gradle file

android {

        ...........................
    defaultConfig {
        ..................  

     multiDexEnabled true
    }


    buildTypes {
        debug {
            minifyEnabled true
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
        innerTest {
            matchingFallbacks = ['debug', 'release']
        }

    }

...................................................
}

dependencies {
    ..................................
    implementation  'com.android.support:multidex:1.0.2'
}
Alainaalaine answered 26/9, 2018 at 9:27 Comment(0)
V
2

By default, Android Studio has a maximum heap size of 1280MB. If you are working on a large project, or your system has a lot of RAM, you can improve performance by increasing the maximum heap size for Android Studio processes, such as the core IDE, Gradle daemon, and Kotlin daemon.

If you use a 64-bit system that has at least 5 GB of RAM, you can also adjust the heap sizes for your project manually. To do so, follow these steps:

Click File > Settings from the menu bar (or Android Studio > Preferences on macOS). Click Appearance & Behavior > System Settings > Memory Settings.

For more Info click

https://developer.android.com/studio/intro/studio-config

enter image description here

Vermiform answered 7/10, 2019 at 9:22 Comment(0)
M
1

Just Change the google play services in gradle (module app) from 9.x.x to the lower version 8.4.0 is work for me

Multifarious answered 11/8, 2016 at 2:12 Comment(1)
This is a sign that all the other Google Play Services version that you use do not match.Erl
S
1

I fixed mine I added to my project > app > libs android volley.jar and my problem was solved

Standup answered 5/1, 2017 at 15:47 Comment(1)
You didn't need a JAR file. compile 'com.android.volley:volley:1.0.0' developer.android.com/training/volley/index.htmlErl
Z
1

If you're facing the problem after updating the google play services 9.8.0 add this to your dependencies :

`dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.google.firebase:firebase-messaging:9.8.0'
compile 'com.google.android.gms:play-services-maps:9.8.0'
compile 'com.google.android.gms:play-services-location:9.8.0'
compile 'com.google.firebase:firebase-database:9.8.0'
compile 'com.google.firebase:firebase-auth:9.8.0'
compile 'com.google.firebase:firebase-crash:9.8.0'
compile 'com.google.maps.android:android-maps-utils:0.4.4'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'

}
Zerla answered 15/2, 2017 at 18:36 Comment(0)
T
1

This happened to me even on debug builds and just cleared all the module level and project level build folders and it worked, yeah just like that.

Transportation answered 3/4, 2018 at 23:31 Comment(1)
Worked for me just now.Singlephase
E
1

For those who still use VS-TACO and have this issue. This happens due to version inconsistency of a jar files.

You still need to add corrections to build.gradle file in platforms\android folder:

 defaultConfig {
        multiDexEnabled true 
 }

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

It's better to do in build-extras.gradle file (which automatically linked to build.gradle file) with all your other changes if there are, and delete all in platforms/android folder, but leave there only build-extras.gradle file. Then just compile.

Economy answered 30/5, 2018 at 10:48 Comment(0)
L
1

None of these answers worked for me. I am using Android studio 3.4.1.

I was able to build the project but Android studio showing this error when I was going to deploy it to mobile device. It turns out it is "instant runs" fault.

Follow this answer: https://mcmap.net/q/112853/-application-installation-failed-in-android-studio

Logic answered 31/5, 2019 at 6:5 Comment(0)
F
0

I really don't know how but the bug gone after I done all this:

1

delete implementation 'com.google.android.gms:play-services:12.0.1'

And add

implementation 'com.google.android.gms:play-services-location:12.0.1'
implementation 'com.google.android.gms:play-services-maps:12.0.1'
implementation 'com.google.android.gms:play-services-places:12.0.1'

2

Update git, jdk, change JDK location in Project structure

3

Delete the build folder in my Project

4

Clean and rebuild the Project

Fash answered 5/5, 2018 at 4:38 Comment(0)
O
0

I disabled the Zip Align Enabled option here

I am having random issues with the latest AndroidStudio (3.2 B1) and tried all the solutions above. I got it working by disabling the "Zip Align Enabled" option in "Build Types"

Obtund answered 26/6, 2018 at 19:52 Comment(0)
Z
0

You can fix this issue by adding a project ext property googlePlayServicesVersion to app/App_Resources/Android/app.gradle file like this:

project.ext {
    googlePlayServicesVersion = "+"
}
Zettazeugma answered 1/10, 2018 at 11:15 Comment(0)
S
0

For me, this turned out to be an unimplemented parcelable class with no datatype [Any]; due to which there was a TODO() constructor created in parcelable implementation of model class.

Hope it helps someone.

@SerializedName("firstTxnDetails")
var firstTxnDetails: Any? = Any()

//in parcelable implementation :

constructor(parcel: Parcel) : this(
            parcel.readInt(),
            parcel.readLong(),
            parcel.readInt(),
            parcel.readDouble(),
            parcel.readLong(),
            TODO("firstTxnDetails"), // -> correct this
            parcel.readString(),
            parcel.readLong(),
            parcel.readParcelable(MasterSavingPlan::class.java.classLoader),
            parcel.readInt(),
            parcel.readString(),
            parcel.readString()) {
    }
Steinman answered 5/1, 2019 at 6:21 Comment(0)
W
0

In my case after invalidate cache and restart the android studio fixed the problem .To do that go to

File -> invalidate cache / Restart

Wiggler answered 21/1, 2019 at 11:33 Comment(0)
A
0

The best way comes from James Riordan's answer from this thread

This can be fixed by updating to Gradle 5.5

The easiest way to do this is to update the wrapper in use:

  • Open gradle/gradle-wrapper.properties

  • Find the line that looks like

distributionUrl=https\://services.gradle.org/distributions/gradle-5.X.X-all.zip
  • Change the version to 5.5-all.zip

Then try running the build again.

Abydos answered 16/7, 2019 at 12:26 Comment(0)
J
0

Add this line to ProGuard-rules.pro file:

-keepparameternames

That helped me while obfuscating library. I was getting zip exception when I add library as dependency.

Johppa answered 15/1, 2020 at 12:14 Comment(0)
R
0

Just add a "multidex-config.txt" in you app directory:

enter image description here

Refined answered 26/3, 2020 at 15:41 Comment(0)
S
0

DEPRECATED

gradle.properties

# ...
android.enableD8.desugaring = true
android.enableIncrementalDesugaring = false
Secede answered 20/11, 2020 at 0:57 Comment(0)
C
0

I have tried android studio max heap size options, still I was getting out of memory error while building the release build. So finally below settings worked for me in gradle.properties file.

org.gradle.jvmargs=-Xmx5120m -XX:MaxPermSize=5120m -XX:+HeapDumpOnOutOfMemoryError

Conveyancing answered 3/8, 2021 at 22:10 Comment(0)
F
-1

I know this is an old question, but I spent a couple of days looking through solutions which didn't work for me so maybe this helps someone else.

My project had a plugin which was throwing an error. I had to remove the plugin and add it again, and suddenly I could make it through the build process.

$ cordova add phonegap-plugin-push
$ cordova plugin add phonegap-plugin-push

I just ran the above and it was solved.

Fancher answered 31/3, 2020 at 14:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.