Android studio 2.0 gradle transformClassesWithDexForDebug 在使用 button "run" 时失败



从android studio 1.5迁移到2.0 后,我遇到了一个问题

在我的一个项目中(只有一个),我不能使用安卓工作室运行按钮,

因此,在gradle任务"transformClassesWithDexForDebug"上构建失败

错误:

: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

更令人沮丧的是,当我使用终端命令时,这并没有发生,在那里有相同的等级任务

./gradlew clean generateDebugSources generateDebugAndroidTestSources mockableAndroidJar prepareDebugUnitTestDependencies assembleDebug

apk文件生成得很好问题出现在MAC和Linux上,因此未指定平台,但未出现在Android Studio 1.5 中

我正在发布我的等级构建文件

提前感谢

    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"

}

几个星期以来,我一直在努力解决这个问题。

现在我找到了解决方法。如果有人遇到同样的问题,关闭Android Studio中的即时运行设置会有所帮助。

我知道这不是一个解决方案,但这是目前最好的事情。

欢呼Wojtek

添加

dexOptions {
    javaMaxHeapSize "4g"
}

在android 中

当我遇到这个问题时,我会重新启动Android Studio(2.0)。然后它就起作用了。不需要编辑渐变文件或关闭即时运行。

我只需要在移动应用程序的build.gradle文件中添加以下行就可以解决这个问题:

安卓{

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

}

依赖项{

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

}

对我来说,在gradle.properties中添加这一行(或注释掉,因为它写在第13行)有效:

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

此外,我还关闭了即时运行(Android Studio 2.1.2)。

我在linux上也遇到了同样的问题。由于某些原因,/build中的一些文件和目录无法删除,即使使用"sudo-rf"也无法删除,这就是我问题的根源。我在MacBookPro中构建了该项目,没有问题。

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

ProGuard似乎在某些地方优化了变量分配,但做得不正确。

尝试通过在proguard-rules.pro:中添加以下行来禁用此优化

-optimizations !code/allocation/variable

重构库帮助我解决了这个问题。这一定有助于从应用模块中删除重复的类。

我发现了许多解决方案,但我通过添加解决了这个问题

Sol 1:build.gradle:中

defaultConfig {
    multiDexEnabled true
}

清理您的项目并重新生成。

Sol 2:如果您在local.properties中仍有问题,请添加

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

Sol 3尽管如此,您仍有问题添加以下提到的依赖项:

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

任何人的解决方案都一定适用于您否则,在应用程序中添加所有3个

接受的答案可能有效,但我将与您分享解决此问题的方法。这是由于添加了额外的库依赖项后达到了最大方法数。

请参阅此处的本指南进行修复,跳到使用Gradle为Multidex配置您的应用程序一节来开门见山。

以上所有内容对我都不起作用,但这个developer.android.come指南对我起了作用:

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

上面写着:

如果您的minSdkVersion设置为21或更高,您所需要做的就是在模块级build.gradle文件中将multiDexEnabled设置为true,如enter code here所示:

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

但是,如果您的minSdkVersion设置为20或更低,则您必须按如下方式使用多点支持库:

修改模块级build.gradle文件以启用multidex,并将multidex库添加为依赖项,如下所示:

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

只需在应用程序的build.gradle文件中设置即可

这对我有效,

  1. 在build.gradle中,将您当前的android版本作为示例3.0.1

    依赖项{classpath'com.android.tools.build:gradle:3.0.1'}

  2. 在渐变特性中,将你的gradle版本改为gradle-4.4distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip

我希望这能有所帮助!

 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>

相关内容

  • 没有找到相关文章

最新更新