IOException:升级到 Android Studio 3.1 时找不到字节码
IOException: Failed to find byte code when upgrade to Android Studio 3.1
昨天,Google 宣布 Android Studio 3.1 在稳定版频道中可用。所以我试一试。
在此之前,我的项目构建成功,但在我将 AS 升级到 3.1 并将 Gradle 构建工具升级到 com.android.tools.build:gradle:3.1.0
之后(它强制将 gradle 包装器升级到 4.4),它失败了除了这个给定的例外:
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.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.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.access0(DefaultTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:104)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.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.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.call(TransformTask.java:221)
at com.android.build.gradle.internal.pipeline.TransformTask.call(TransformTask.java:217)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
... 47 more
我已经进行了完全彻底的重建,甚至 File-> Invalidate Caches/Restart..,但它是仍然无法正常工作。
有人知道怎么解决吗?谢谢。
首先进入构建菜单并清理项目。清理后重建项目。
如果不起作用,请尝试在构建 gradle 文件中添加此行:
defaultConfig {
multiDexEnabled true
}
对于依赖:
dependencies
{
compile 'com.android.support:multidex:1.0.0'
}
您需要尝试清理并重建项目。如果问题仍然存在,请删除项目中的 .gradle
文件夹。最后,如果 none 有效,请使用 Android Studio 菜单中的 File-> Invalidate Caches/Restart..
。
有 an issue,他们承诺会在 3.2 中修复。在那之前,如果您不想关闭即时 运行,您可能必须回滚到 Android Studio 3.0。为什么他们不想为此发布修补程序,我不知道。似乎是一个非常重要的错误。
参见:
我建议对该问题进行投票,也许这会促使他们尽快发布修复程序。
禁用 Instant 运行 对我有效
正如@Malcolm 所说,这是一个 Android Studio 3.1 问题。
如果您不想将 Android Studio 3.1 恢复到 3.0,您可以禁用 Instant 运行。
如果您不想将 Android Studio 3.1 恢复到 3.0,并且确实需要 Instant 运行,您可以编辑 build.gradle 和 gradle-wrapper.properties 如下所示:
com.android.tools.build:gradle:3.1.0
-> com.android.tools.build:gradle:3.0.1
distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip
-> distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
正如@Malcolm 所说,这个问题与 Android Studio 3.1 有关。
如果我尝试在 Android 5.1 启用 Instant 运行 的设备上 运行,它仍然在 Android Studio 3.1.2 上发生。
使缓存无效、清除/重建项目对我不起作用。
当我切换到 Android 7.0 的设备时,问题已解决,但我认为 Android 6.0+ 也可以。如果您能够切换设备,请尝试一下。无需禁用 Instant 运行.
禁用即时 运行 后,我遇到了同样的问题。应用程序在 运行 时崩溃并抛出 noClassDefFound
错误。在我的例子中,我使用的是forEach
Java 8 在 Hashmap 而不是 kotlin one..
上的 lambda 函数
A post here and similar question 对此进行了描述。
您必须在键和值两边使用括号。例如:
dataSet.forEach { (header, dataList) -> }
这将确保使用 kotlin 函数。
将 gradle 构建工具从 com.android.tools.build:gradle:3.1.1
降级到 com.android.tools.build:gradle:3.0.1
适合我。
如果您遇到 unexpected/weird/stupid 此类错误,很可能是因为
Instant run
禁用它并重试
昨天,Google 宣布 Android Studio 3.1 在稳定版频道中可用。所以我试一试。
在此之前,我的项目构建成功,但在我将 AS 升级到 3.1 并将 Gradle 构建工具升级到 com.android.tools.build:gradle:3.1.0
之后(它强制将 gradle 包装器升级到 4.4),它失败了除了这个给定的例外:
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.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.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.access0(DefaultTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:104)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.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.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.call(TransformTask.java:221)
at com.android.build.gradle.internal.pipeline.TransformTask.call(TransformTask.java:217)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
... 47 more
我已经进行了完全彻底的重建,甚至 File-> Invalidate Caches/Restart..,但它是仍然无法正常工作。
有人知道怎么解决吗?谢谢。
首先进入构建菜单并清理项目。清理后重建项目。
如果不起作用,请尝试在构建 gradle 文件中添加此行:
defaultConfig {
multiDexEnabled true
}
对于依赖:
dependencies
{
compile 'com.android.support:multidex:1.0.0'
}
您需要尝试清理并重建项目。如果问题仍然存在,请删除项目中的 .gradle
文件夹。最后,如果 none 有效,请使用 Android Studio 菜单中的 File-> Invalidate Caches/Restart..
。
有 an issue,他们承诺会在 3.2 中修复。在那之前,如果您不想关闭即时 运行,您可能必须回滚到 Android Studio 3.0。为什么他们不想为此发布修补程序,我不知道。似乎是一个非常重要的错误。
参见:
我建议对该问题进行投票,也许这会促使他们尽快发布修复程序。
禁用 Instant 运行 对我有效
正如@Malcolm 所说,这是一个 Android Studio 3.1 问题。
如果您不想将 Android Studio 3.1 恢复到 3.0,您可以禁用 Instant 运行。
如果您不想将 Android Studio 3.1 恢复到 3.0,并且确实需要 Instant 运行,您可以编辑 build.gradle 和 gradle-wrapper.properties 如下所示:
com.android.tools.build:gradle:3.1.0
-> com.android.tools.build:gradle:3.0.1
distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip
-> distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
正如@Malcolm 所说,这个问题与 Android Studio 3.1 有关。
如果我尝试在 Android 5.1 启用 Instant 运行 的设备上 运行,它仍然在 Android Studio 3.1.2 上发生。
使缓存无效、清除/重建项目对我不起作用。
当我切换到 Android 7.0 的设备时,问题已解决,但我认为 Android 6.0+ 也可以。如果您能够切换设备,请尝试一下。无需禁用 Instant 运行.
禁用即时 运行 后,我遇到了同样的问题。应用程序在 运行 时崩溃并抛出 noClassDefFound
错误。在我的例子中,我使用的是forEach
Java 8 在 Hashmap 而不是 kotlin one..
A post here and similar question
dataSet.forEach { (header, dataList) -> }
这将确保使用 kotlin 函数。
将 gradle 构建工具从 com.android.tools.build:gradle:3.1.1
降级到 com.android.tools.build:gradle:3.0.1
适合我。
如果您遇到 unexpected/weird/stupid 此类错误,很可能是因为
Instant run
禁用它并重试