IOException:升级到Android Studio 3.1时无法find字节代码

昨天,谷歌宣布Android Studio 3.1现在可以在稳定发布渠道下载。 所以我决定尝试一下。

在此之前,我的项目已成功构建,但在我将AS升级到3.1并将gradle构建工具升级到com.android.tools.build:gradle:3.1.0 (它强制升级gradle包装器4.4)后,它失败并出现以下exception:

 java.lang.RuntimeException: com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: java.io.IOException: Failed to find byte code for android/hardware/camera2/CameraManager$TorchCallback at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:55) at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:104) at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:212) at sun.reflect.GeneratedMethodAccessor309.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73) at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:46) at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39) at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121) at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336) at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328) at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199) at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70) at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51) at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62) at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54) at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60) at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97) at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87) at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.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:54) at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34) at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248) at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336) at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328) at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199) at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110) at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241) at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98) at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626) at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63) at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) at java.lang.Thread.run(Thread.java:745) Caused by: com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: java.io.IOException: Failed to find byte code for android/hardware/camera2/CameraManager$TorchCallback at com.android.build.gradle.internal.transforms.InstantRunTransform.doTransform(InstantRunTransform.java:312) at com.android.build.gradle.internal.transforms.InstantRunTransform.transform(InstantRunTransform.java:178) at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:221) at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:217) at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102) ... 47 more 

我已经做了一个完全干净的重建,甚至File-> Invalidate Caches/Restart.. ,但它仍然无法正常工作。

有谁知道如何解决这个问题? 谢谢。

Solutions Collecting From Web of "IOException:升级到Android Studio 3.1时无法find字节代码"

有一个问题 ,他们承诺在3.2中修复。 在此之前,如果您不想关闭即时运行,则可能需要回滚到Android Studio 3.0。 为什么他们不想为此发布修补程序,我不知道。 似乎是一个非常重要的错误。

看到:

在此处输入图像描述

我建议投票支持这个问题,也许这会激励他们尽快发布修复程序。

正如@Malcolm所说,这是一个Android Studio 3.1问题。

如果您不想将Android Studio 3.1还原为3.0,则可以禁用“即时运行”。

如果您不想将Android Studio 3.1还原为3.0,并且需要立即运行,则可以编辑build.gradlegradle-wrapper.properties,如下所示:

  1. com.android.tools.build:gradle:3.1.0

    – > com.android.tools.build:gradle:3.0.1

  2. distributionUrl = https://services.gradle.org/distributions/gradle-4.4-all.zip

    – > distributionUrl = https://services.gradle.org/distributions/gradle-4.1-all.zip

禁用即时运行对我有用

首先去构建菜单和清理项目。 清洁后重建项目。

如果不起作用,请尝试在构建gradle文件中添加此行:

  defaultConfig { multiDexEnabled true } 

对于依赖:

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

您需要尝试清理并重建项目。 如果问题仍然存在,请删除项目中的.gradle文件夹。 最后,如果没有,请使用Android Studio菜单中的File-> Invalidate Caches/Restart..

在禁用即时运行后我遇到了同样的问题。应用程序在运行时崩溃并抛出了noClassDefFound错误。在我的情况下,我在Hashmap上使用Java 8的forEach lambda函数而不是kotlin一个..

这里的post和类似问题描述了这一点。 您必须在键和值周围使用括号。 例如:

 dataSet.forEach { (header, dataList) -> } 

这将确保使用kotlinfunction。

正如@Malcolm所说,这个问题与Android Studio 3.1有关。

如果我尝试在启用了Instant Run的Android 5.1设备上运行,它仍会在Android Studio 3.1.2上发生。

无效缓存,清除/重建项目对我来说不起作用。

当我切换到安装了Android 7.0的设备时,问题就解决了,但我认为Android 6.0+也可以运行。 如果您能够切换设备,请尝试一下。 无需禁用即时运行。