ChatGPT解决这个技术问题 Extra ChatGPT

Android- Error:Execution failed for task ':app:transformClassesWithDexForRelease'

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

could you post your app's build.gradle file?
@Harisewak i have updated the question, Please take a look at it now
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.
@Harisewak 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
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 problem

A
Andrii Abramov

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
}

"local.properties" is that a file name or a configuration value? Where (eg: in which folder) is it located inside the project?
The local.properties file goes in the project's root level. if you have a problem about multiDex--> developer.android.com/studio/build/multidex.html
I just inserted multiDexEnabled true in my build.gradle and the magic was done. Thank you.
I don't know what all of this means, but it worked for me!
On API <21, multiDexEnabled without extending Application class from MultiDexApplication will lead to NoClassDefFoundErrors.
A
AgataB

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

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 22
    multiDexEnabled = true
}

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.html
F
Faysal Ahmed

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.


same issue with jackrabbit-standalone-2.12.2.jar. If I add it to project then the issue raises.
@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.
but i am not using any jar file then why i am facing this problem
Can you please provide more details explanation for this solution
@IvanMilisavljevic You can use Gradle now, not JAR files. developers.google.com/android/guides/setup#split
A
Ahmad Aghazadeh

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:

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 } Try your build again.

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


Saved my day! Cheers!
The best...I've been roaming around for hours..thanks!
R
Ruchir Baronia

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:

Go to SDK manager, and install any updates to your dependencies 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 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


Brilliant! Works perfectly!
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.
You saved my day!
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...)
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 :)
M
Mohammedsalim Shivani

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
}

P
Prokash Sarkar

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.


minifyEnable true gives me exception - Below is my Question, stackoverflow.com/questions/51720018/… Please help me with this.
K
Kalaivanan

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


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.0
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.
Your should not use this. Please selectively compile those libraries. developers.google.com/android/guides/setup#split
where to change ....above changes ? can you please tell me the file name ?
d
devDeejay

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.


I had the same issue. Disabling Instant Run and enabling it again worked for me.
Fixed my issue too. Mind you - Instant Run is useful so I hope there's a better fix soon
Aaaaarg they always enable this on the update and it always causes so many issues.
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!
Disabling Instant run worked for me with this issue. Didn't get the error again.
C
Community

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


S
Selim Özbudak

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

org.gradle.jvmargs=-XX:MaxHeapSize\=2048m -Xmx2048m

J
Jonathon Ogden

Remove the jar files in your gradle Sync it Copy that jar and sync it

This worked for me.


Can you be more specific which jar files? Is it the jar files inside our project gradle/wrapper?
Don't know what it is with people mentioning "the jars". That doesn't explain anything.
S
Satan Pandeya

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


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'
C
Crime_Master_GoGo

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.


K
KostasKol

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


c
chancyWu

just setting the multiDexEnabled to true worked fine.

    defaultConfig 
    {
        multiDexEnabled true     
    }

L
Leos Literak

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


Not Working Any Other chance>
Changing it to what?
I erased it (I was checking it now) and it kept working
M
Mark

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);
}

G
Ganesh P

add this line in your build.gradle

 defaultConfig {
    ............
    aaptOptions.cruncherEnabled = false
    aaptOptions.useNewCruncher = false
    compileOptions.encoding = 'ISO-8859-1'
    multiDexEnabled true
}

Which "line" did you add here?
B
Braj Bhushan Singh

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"
}

k
kriztho

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.


K
Kush

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'
}

v
vinod

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

https://i.stack.imgur.com/P8glf.png


N
Nazwa Asshiba

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


This is a sign that all the other Google Play Services version that you use do not match.
M
MarJose

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


You didn't need a JAR file. compile 'com.android.volley:volley:1.0.0' developer.android.com/training/volley/index.html
i
ismail alaoui

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'

}

P
Panduka DeSilva

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.


Worked for me just now.
S
Serg Tomcat

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.


K
Keivan

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://stackoverflow.com/a/42695197/3197467


K
Kyo Huu

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


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now