Yesterday, Google announced that Android Studio 3.1 is available in the stable release channel. So I give it a try.
Before of that my project was build successfully but after I upgraded AS to 3.1 and Gradle build tool to com.android.tools.build:gradle:3.1.0
(it forced upgrade gradle wrapper to 4.4), it failed with this given 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
I'm already do a full clean rebuild or even File-> Invalidate Caches/Restart.., but it's still not working.
Anyone know how to solve this? Thank you.
There is an issue, which they promise to fix in 3.2. Until then you probably have to roll back to Android Studio 3.0 if you don't want to turn off instant run. Why they don't want to release a hotfix for this, I don't know. Seems to be a pretty important bug.
See:
I suggest voting for the issue, maybe this will motivate them to release the fix sooner.
Just as @Malcolm said, this is an Android Studio 3.1 issue.
If you don't want to revert Android Studio 3.1 to 3.0, you can disable Instant Run.
If you don't want to revert Android Studio 3.1 to 3.0, and do need Instant Run, you can edit build.gradle and gradle-wrapper.properties like below:
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
Disabling Instant Run worked for me
if you get unexpected/weird/stupid errors like this it's most probably because of
Instant run
disable it and try again
Firstly go to build menu and clean project. After cleaning rebuild the project.
If doesn't work then, Try to add this line in build gradle file:
defaultConfig {
multiDexEnabled true
}
For dependency:
dependencies
{
compile 'com.android.support:multidex:1.0.0'
}
I had the same issue, after disabling instant run.. The app was crashing at runtime and threw a noClassDefFound
error.. In my case I was using the forEach
lambda function of Java 8 on Hashmap instead of kotlin one..
A post here and similar question here describes this. You have to use parentheses around the key and value. eg:
dataSet.forEach { (header, dataList) -> }
This will ensure to use the kotlin function.
You ned to try clean and rebuild the project. If the problem still persist, remove the .gradle
folder inside your project. Last, if none works, Use File-> Invalidate Caches/Restart..
from Android Studio menu.
As @Malcolm said, the issue is related to Android Studio 3.1.
It is still happening on Android Studio 3.1.2 if I try to run on a device with Android 5.1 while Instant Run enabled.
Invalidating caches, clearing / rebuilding project didn't work for me.
The issue was solved when I've switched to a device with Android 7.0 but I think Android 6.0+ would also work. If you are able to switch the device, give it a try. No need to disable Instant Run.
Downgrade the gradle build tool from com.android.tools.build:gradle:3.1.1
to com.android.tools.build:gradle:3.0.1
works for me.
来源:https://stackoverflow.com/questions/49525708/ioexception-failed-to-find-byte-code-when-upgrade-to-android-studio-3-1