gradle android-studio-2.0

Android studio 2.0 gradle transformClassesWithDexForDebug falla cuando se usa el botón "ejecutar"



android-studio-2.0 (14)

Tengo un problema después de la migración de Android Studio 1.5 a 2.0

En uno de mis proyectos (solo uno) no puedo usar el botón de ejecución de Android Studio,

porque entonces, la compilación falla en la tarea gradle "transformClassesWithDexForDebug"

con error:

:app:transformClassesWithDexForDebug AGPBI: {"kind":"error","text":"Uncaught translation error: com.android.dx.cf.code.SimException: local variable type mismatch: attempt to set or access a value of type java.lang.Object using a local variable of type int. This is symptomatic of .class transformation tools that ignore local variable information.","sources":[{}]} AGPBI: {"kind":"error","text":"1 error; aborting","sources":[{}]} FAILED FAILURE: Build failed with an exception. * What went wrong: 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 ''/usr/lib/jvm/java-8-oracle/bin/java'''' finished with non-zero exit value 1 * Try: Run with --info or --debug option to get more log output. * Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task '':app:transformClassesWithDexForDebug''. 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.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:46) at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35) at org.gradle.tooling.internal.provider.runner.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:58) 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: 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 ''/usr/lib/jvm/java-8-oracle/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) ... 70 more Caused by: 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 ''/usr/lib/jvm/java-8-oracle/bin/java'''' finished with non-zero exit value 1 at com.android.build.gradle.internal.transforms.DexTransform.transform(DexTransform.java:425) 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) ... 79 more Caused by: 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 ''/usr/lib/jvm/java-8-oracle/bin/java'''' finished with non-zero exit value 1 at com.android.ide.common.internal.WaitableExecutor.waitForTasksWithQuickFail(WaitableExecutor.java:119) at com.android.build.gradle.internal.transforms.DexTransform.transform(DexTransform.java:365) ... 82 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 ''/usr/lib/jvm/java-8-oracle/bin/java'''' finished with non-zero exit value 1 at com.android.builder.core.AndroidBuilder.runDexer(AndroidBuilder.java:1473) at com.android.builder.core.AndroidBuilder.preDexLibraryNoCache(AndroidBuilder.java:1659) at com.android.builder.internal.compiler.PreDexCache.preDexLibrary(PreDexCache.java:119) at com.android.builder.core.AndroidBuilder.preDexLibrary(AndroidBuilder.java:1614) at com.android.build.gradle.internal.transforms.DexTransform$PreDexTask.call(DexTransform.java:475) at com.android.build.gradle.internal.transforms.DexTransform$PreDexTask.call(DexTransform.java:429) Caused by: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ''command ''/usr/lib/jvm/java-8-oracle/bin/java'''' finished with non-zero exit value 1 at com.android.builder.core.AndroidBuilder.runDexer(AndroidBuilder.java:1457) ... 5 more Caused by: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ''command ''/usr/lib/jvm/java-8-oracle/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:1465) at com.android.builder.core.AndroidBuilder$2.call(AndroidBuilder.java:1457) Caused by: org.gradle.process.internal.ExecException: Process ''command ''/usr/lib/jvm/java-8-oracle/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

lo que es aún más frustrante, esto no sucede cuando estoy usando el comando de terminal donde están las mismas tareas de gradle

./gradlew clean generateDebugSources generateDebugAndroidTestSources mockableAndroidJar prepareDebugUnitTestDependencies assembleDebug

Los archivos apk se generan muy bien. El problema aparece en MAC y Linux, por lo que no se especifica en la plataforma, pero no aparece en Android Studio 1.5.

Estoy publicando mi archivo gradle.build

Muchas gracias de antemano

apply plugin: ''com.android.application'' apply plugin: ''com.neenbedankt.android-apt'' apply plugin: ''kotlin-android'' apply plugin: ''kotlin-android-extensions'' buildscript { repositories { jcenter() } dependencies { classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" } } android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.wojtek.MyProject" minSdkVersion 19 targetSdkVersion 23 versionCode 4 versionName "0.1.3" testInstrumentationRunner ''com.wojtek.my_project.AndroidTestRunner'' } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile(''proguard-android.txt''), ''proguard-rules.pro'' } } lintOptions { abortOnError false } testOptions { unitTests.returnDefaultValues = true } } dependencies { compile fileTree(dir: ''libs'', include: [''*.jar'']) compile "com.android.support:support-annotations:$support_version" compile "com.android.support:appcompat-v7:$support_version" compile "com.android.support:recyclerview-v7:$support_version" compile "com.android.support:cardview-v7:$support_version" compile "com.android.support:design:$support_version" compile "com.android.support:palette-v7:$support_version" compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "io.reactivex:rxkotlin:$rx_kotlin" compile "org.jetbrains.anko:anko-sqlite:$anko_version" compile ''io.reactivex:rxandroid:1.1.0'' compile "com.squareup.retrofit2:retrofit:$retrofitVersion" compile ''com.squareup.okhttp3:logging-interceptor:3.0.1'' compile "com.squareup.retrofit2:converter-gson:$retrofitVersion" compile "com.squareup.retrofit2:adapter-rxjava:$retrofitVersion" apt "com.google.dagger:dagger-compiler:${daggerVersion}" compile "com.google.dagger:dagger:${daggerVersion}" provided ''org.glassfish:javax.annotation:10.0-b28'' compile ''com.squareup.picasso:picasso:2.5.2'' //TEST****************************************************************************************** testCompile ''junit:junit:4.12'' testCompile ''org.mockito:mockito-core:1.10.19'' androidTestCompile "com.android.support:support-annotations:$support_version" androidTestCompile "com.android.support.test.espresso:espresso-core:$ESSPRESSO_VERSION" androidTestCompile ("com.android.support.test.espresso:espresso-contrib:$ESSPRESSO_VERSION"){ exclude group: ''com.android.support'', module: ''appcompat'' exclude group: ''com.android.support'', module: ''support-v4'' exclude module: ''recyclerview-v7'' } androidTestCompile ''com.android.support.test:runner:0.4.1'' androidTestCompile ''com.android.support.test:rules:0.4.1'' androidTestCompile ''org.mockito:mockito-core:1.10.19'' androidTestCompile ''com.google.dexmaker:dexmaker:1.2'' androidTestCompile ''com.google.dexmaker:dexmaker-mockito:1.2'' androidTestApt "com.google.dagger:dagger-compiler:$daggerVersion" }


Descubrí muchas soluciones pero resolví este problema agregando:

Sol 1: En build.gradle :

defaultConfig { multiDexEnabled true }

Limpia tu proyecto y reconstruye.

Sol 2: Si todavía tienes problemas en agregar local.properties ,

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

Sol 3 Aún así, tienes problema agregar a continuación la dependencia mencionada:

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

Cualquier solución definitivamente funcionará para usted. De lo contrario agregue los 3 en su aplicación.


Durante pocas semanas estuve tratando de resolver este problema.

Ahora he encontrado una solución para eso. Si alguien enfrenta el mismo problema, desactivar la ejecución instantánea Ejecutar en la configuración de Android Studio ayudará.

Sé que no es una solución pero es lo mejor por ahora.

Saludos Wojtek


Esto funciona para mi

  1. En build.gradle, ponga su versión actual de Android como ejemplo 3.0.1

    dependencias {classpath ''com.android.tools.build:gradle: 3.0.1 ''}

  2. En gradle-wrapper.properties, cambie su versión de gradle como ejemplo gradle-4.4 distributionUrl = https: //services.gradle.org/distributions/ gradle-4.4 -all.zip

¡Espero que esto pueda ayudar!


La respuesta aceptada podría funcionar, pero compartiré lo que solucionó esto conmigo. Fue debido a la cantidad máxima de métodos alcanzados después de la adición de una dependencia de biblioteca adicional.

Vea esta guía aquí para corregir, pase a la sección Configuración de su aplicación para Multidex con Gradle para llegar al punto.


Nada de lo anterior funcionó para mí, pero esta guía developer.android.come funcionó para mí:

https://developer.android.com/studio/build/multidex.html

Dice lo siguiente:

Si su minSdkVersion está configurado a 21 o superior, todo lo que necesita hacer es establecer multiDexEnabled en verdadero en su archivo build.gradle a nivel de módulo, como enter code here muestra aquí:

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

Sin embargo, si su minSdkVersion está configurado a 20 o menos, entonces debe usar la biblioteca de soporte multidex de la siguiente manera:

Modifique el archivo build.gradle a nivel de módulo para habilitar multidex y agregue la biblioteca multidex como una dependencia, como se muestra aquí:

android { defaultConfig { ... minSdkVersion 15 targetSdkVersion 25 multiDexEnabled true } ... } dependencies { compile ''com.android.support:multidex:1.0.1'' }


Para mí, agregar esta línea (o comentar porque está escrita en la línea 13) en gradle.properties funcionó:

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

También desactivé la ejecución instantánea (Android Studio 2.1.2).


Reinicio Android Studio (2.0) cuando tengo este problema. Entonces funciona. No es necesario editar archivos gradle ni desactivar la ejecución instantánea.


Tengo el mismo problema, en linux. Por alguna razón, algunos archivos y direcciones dentro de / build no se pueden eliminar, ni siquiera con ''sudo -rf'', y este es el origen del problema para mí. Construí el proyecto en una MacBookPro y no hay problema.


Todo lo que me llevó a solucionar este problema fue agregar las siguientes líneas al archivo build.gradle para la aplicación móvil:

...

androide {

... // Enabling multidex support. multiDexEnabled true } dexOptions { javaMaxHeapSize "4g" } ...

}

dependencias {

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

}


añadir

dexOptions { javaMaxHeapSize "4g" }

en android


attempt to set or access a value of type java.lang.Object using a local variable of type int

Parece que en algún lugar ProGuard optimiza la asignación de variables, pero lo hace incorrectamente.

Intente deshabilitar esta optimización agregando la línea a continuación en su proguard-rules.pro :

-optimizations !code/allocation/variable


Refactorizar la biblioteca me ayudó a resolver este problema. Esto debe haber ayudado a eliminar clases duplicadas de la biblioteca o del módulo de la aplicación .


defaultConfig { minSdkVersion 16 targetSdkVersion 25 multiDexEnabled true }

Solo configura esto en el archivo build.gradle de tu aplicación


android { compileSdkVersion 23 buildToolsVersion "24.0.0" defaultConfig { ... minSdkVersion 14 targetSdkVersion 23 ... // Enabling multidex support. multiDexEnabled true } ... } dependencies { compile ''com.android.support:multidex:1.0.0'' } repositories { mavenCentral() } <application ... android:largeHeap="true" android:supportsRtl="true" android:name="android.support.multidex.MultiDexApplication"> </application>