IOException: could not find byte code when upgrading to Android Studio 3.1

Google announced yesterday that Android Studio 3.1 is now available for download in the stable release channel. So I decided to give it a try.

Before that, my project was successfully created, but after I upgraded AS to 3.1 and gradle the build tool to com.android.tools.build:gradle:3.1.0 (he forcibly updated gradle wrapper 4.4), he 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 am already doing a complete clean rebuild or even File-> Invalidate Caches/Restart.. but it still does not work.

Does anyone know how to solve this? Thanks.

+32
source share
9 answers

There is a problem that they promise to fix in 3.2. Before that, you will probably have to roll back to Android Studio 3.0 if you do not want to disable instant launch. Why they do not want to release corrections for this, I do not know. It seems like a pretty important bug.

See:

enter image description here

I suggest voting for the problem, perhaps this will prompt them to release the fix earlier.

+53
source

As @Malcolm said, this is a problem of Android Studio 3.1.

If you do not want to return Android Studio 3.1 to version 3.0, you can disable Instant Run.

If you do not want to return Android Studio 3.1 to version 3.0 and you need Instant Run, you can edit build.gradle and gradle-wrapper.properties, as shown below:

  1. com.android.tools.build:gradle{.1.0

    β†’ com.android.tools.build:gradlehaps.0.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

+22
source

Disabling Instant Run worked for me

+10
source

First go to the build menu and clear the project. After cleaning, rebuild the project.

If this does not work, try adding this line to the build gradle file:

  defaultConfig { multiDexEnabled true } 

Dependence:

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

I had the same problem after disabling instant start .. The noClassDefFound application at runtime and the noClassDefFound error .. In my case, I used the forEach lambda function from Java 8 on Hashmap instead of kotlin-1.

A post here and a similar question here describes this. You must use parentheses around the key and value. eg:

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

This will ensure the use of the kotlin function.

+1
source

You should try to clean and rebuild the project. If the problem still persists, delete the .gradle folder inside your project. Finally, if nothing works, use File-> Invalidate Caches/Restart.. in the Android Studio menu.

0
source

As @Malcolm said, the problem is with Android Studio 3.1.

This still happens in Android Studio 3.1.2 if I try to start the device with Android 5.1 with Instant Run turned on.

Destroying caches, cleaning / rebuilding the project did not help me.

The problem was resolved when I switched to a device with Android 7.0, but I think Android 6. 0+ will also work. If you can switch the device, try. There is no need to disable instant start.

0
source

Downgrade the Gradle build tool from com.android.tools.build:gradle:3.1.1 to com.android.tools.build:gradle:3.0.1 .

0
source

if you get unexpected / strange / stupid errors like this, this is most likely due to

Instant start

unplug it and try again

0
source

Source: https://habr.com/ru/post/1276121/


All Articles