Android studio 2.0 gradle transformClassesWithDexForDebug fails when using button “run”

妖精的绣舞 提交于 2019-12-29 19:24:02

问题


I have a problem after migration from android studio 1.5 to 2.0

In one of my project (only one) i can't use android studio run button,

because then, build fails on gradle task "transformClassesWithDexForDebug"

with 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

what is even more frustrating, this is not happening when I am using terminal command where are the same gradle tasks

./gradlew clean generateDebugSources generateDebugAndroidTestSources mockableAndroidJar prepareDebugUnitTestDependencies assembleDebug

The apk files are nicely generated Problem appears on MAC and Linux, so it is not platform specified, but it not appears in Android Studio 1.5

I am posting my gradle.build file

Many thanks in advance

    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"


}

回答1:


for few weeks i was trying to solve this problem.

Now I have found workaround for that. If someone face the same problem, turning off instant Run in Android Studio settings will help.

I know that it is not a solution but it is the best thing for now.

cheers Wojtek




回答2:


add

dexOptions {
    javaMaxHeapSize "4g"
}

in android




回答3:


I restart Android Studio (2.0) when I have this problem. Then it works. No edit in gradle files or turn off instant run required.




回答4:


All it took to fix this issue for me was to add the following lines to the build.gradle file for the mobile app:

...

android {

    ...

    // Enabling multidex support.
    multiDexEnabled true
}

dexOptions {
    javaMaxHeapSize "4g"
}

...

}

dependencies {

...

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

...

}




回答5:


For me adding this line (or commenting out because it is written there in the 13th line) in gradle.properties worked:

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

Also I turned off Instant run (Android Studio 2.1.2).




回答6:


I have the same problem, on linux. For some reason, some files and dirs inside /build can not be deleted, not even with 'sudo -rf', and this is the origin of the problem for me. I built the project in a MacBookPro and no problem.




回答7:


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

Seems like in some place ProGuard optimizes variable allocation, but does it incorrectly.

Try to disable this optimization by adding the line below in your proguard-rules.pro:

-optimizations !code/allocation/variable




回答8:


Refactoring the library helped me resolving this issue. This must have helped in removing duplicate classes from the library or from the app module.




回答9:


I discovered many solutions but I solved this issue by adding:

Sol 1: In build.gradle:

defaultConfig {
    multiDexEnabled true
}

Clean your project and rebuild.

Sol 2: If still you have issue in local.properties add,

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

Sol 3 Still, You have issue add below mentioned dependency:

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

Anyone solution will definitely work for you. Otherwise add all 3 in your application.




回答10:


The accepted answer might work, but I'll share what fixed this with me. It was due to the maximum number of methods being reached after the addition of an additional library dependency.

See this guide here to fix, skip down to Configuring Your App for Multidex with Gradle section to get to the point.




回答11:


None of the above worked for me, but this developer.android.come guide worked out for me:

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

It says the following:

If your minSdkVersion is set to 21 or higher, all you need to do is set multiDexEnabled to true in your module-level build.gradle file, as enter code hereshown here:

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

However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library as follows:

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

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

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



回答12:


     defaultConfig {

    minSdkVersion 16
    targetSdkVersion 25  

    multiDexEnabled true
}

Just set this in your app's build.gradle file




回答13:


This works for me,

  1. In build.gradle, put your current android version as example 3.0.1

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

  2. In gradle-wrapper.properties, change your gradle version as example gradle-4.4 distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip

I hope this can help!




回答14:


 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>


来源:https://stackoverflow.com/questions/36593582/android-studio-2-0-gradle-transformclasseswithdexfordebug-fails-when-using-butto

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