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

廉价感情. 提交于 2019-11-25 18:47:10
aemre

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

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

defaultConfig {     minSdkVersion 14     targetSdkVersion 22     multiDexEnabled = true } 
Sheraz Ahmad Khilji

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.

PN10

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.

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

thilina Kj

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.

Mwongera808

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 } 

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

Well, I believe the question is answered and being accepted. But I am going to wrote what I face 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

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.

Bharath
  1. Remove the jar files in your gradle
  2. Sync it
  3. Copy that jar and sync it

This worked for me.

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

org.gradle.jvmargs=-XX:MaxHeapSize\=2048m -Xmx2048m 
Marco Muñoz

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

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

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.

wanjiku

just setting the multiDexEnabled to true worked fine.

    defaultConfig      {         multiDexEnabled true          } 
Yuri Misyac

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

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

add this line in your build.gradle

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

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

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

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

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

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.

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.

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

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

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.

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"

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' } 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!