昨天,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$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
我已经进行了全面清洁重建,甚至文件 - > 使缓存无效/重新启动.. ,但它仍无效。
任何人都知道如何解决这个问题?谢谢。
答案 0 :(得分:54)
有an issue,他们承诺在3.2中修复。在此之前,如果您不想关闭即时运行,则可能需要回滚到Android Studio 3.0。为什么他们不想为此发布修补程序,我不知道。似乎是一个非常重要的错误。
请参阅:
我建议投票支持这个问题,也许这会激励他们尽快发布修复程序。
答案 1 :(得分:24)
正如@Malcolm所说,这是一个Android Studio 3.1问题。
如果您不想将Android Studio 3.1还原为3.0,则可以停用即时运行。
如果您不想将Android Studio 3.1还原为3.0,并且需要立即运行,则可以修改 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
答案 2 :(得分:11)
禁用即时运行为我工作
答案 3 :(得分:2)
如果您遇到这样的意外/奇怪/愚蠢的错误,很可能是因为
即时运行
禁用它,然后重试
答案 4 :(得分:1)
首先去构建菜单并清理项目。清洁后重建项目。
如果不起作用,请尝试在构建gradle文件中添加此行:
.page-header {
background-image: url(https://source.unsplash.com/o3TZx8_j7FE);
background-position: 100%;
background-size: cover;
min-height: 50vh;
max-height: 999px;
width: 100%;
}
依赖:
defaultConfig {
multiDexEnabled true
}
答案 5 :(得分:1)
在禁用即时运行后,我遇到了同样的问题。该应用程序在运行时崩溃并引发了noClassDefFound
错误。在我的情况下,我在Java 8上使用了forEach
lambda函数哈希图,而不是kotlin一个。.
帖子here和类似问题here对此进行了描述。 您必须在键和值周围使用括号。例如:
dataSet.forEach { (header, dataList) -> }
这将确保使用kotlin函数。
答案 6 :(得分:0)
您需要尝试清理并重建项目。如果问题仍然存在,请删除项目中的.gradle
文件夹。最后,如果无效,请使用Android Studio菜单中的File-> Invalidate Caches/Restart..
。
答案 7 :(得分:0)
正如@Malcolm所说,这个问题与Android Studio 3.1有关。
如果我尝试在安装了Instant Run的Android 5.1设备上运行,它仍会在Android Studio 3.1.2上发生。
缓存无效,清除/重建项目并不适合我。
当我转换到使用Android 7.0的设备时,问题就解决了,但我认为Android 6.0+也可以运行。如果您能够切换设备,请尝试一下。无需禁用即时运行。
答案 8 :(得分:0)
将gradle构建工具从com.android.tools.build:gradle:3.1.1
降级到com.android.tools.build:gradle:3.0.1
对我来说有用。