35

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.

nhoxbypass
  • 9,695
  • 11
  • 48
  • 71
  • 11
    Try disabling instant run. It might just work! – Ahmed Hegazy Mar 28 '18 at 04:17
  • 2
    I had the same problem and did what you went through - clean, invalidate, restart to to avail. Fortunately, the suggestion by @AhmedHegazy - disabling instant run works for me. I still hope to find a solution without disabling instant-run. – Hong Mar 29 '18 at 07:02
  • @Hong thank you, but instant run is very important to me :( – nhoxbypass Mar 29 '18 at 07:14
  • Concur. This is why I hope for a solution without disabling it. Hope Google will fix the bug ASAP. – Hong Mar 29 '18 at 07:17
  • 1
    Disabling instant run works just fine, but of course if you need it is better to revert it as other people mentioned... Bear in mind if you are looking to compile the app you can still do it via gradle, the exception you are getting is just an intant run thing. – Javier Mendonça May 11 '18 at 07:23
  • This issue has been fixed in 3.3.0 – Monish Kamble May 03 '19 at 16:09

9 Answers9

54

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:

enter image description here

I suggest voting for the issue, maybe this will motivate them to release the fix sooner.

Malcolm
  • 41,014
  • 11
  • 68
  • 91
  • Thank you! Hope they will release the fix soon. – nhoxbypass Apr 04 '18 at 01:51
  • This isssue was already fixed in Android Studio 3.2 Canary 10 - https://androidstudio.googleblog.com/2018/04/android-studio-32-canary-10-now.html. Update on canary channel or wait for a stable 3.2 release ;) – lomza Apr 13 '18 at 07:41
  • 1
    See how to `disable Instant Run` here: https://stackoverflow.com/questions/46999669/how-to-disable-instant-run-for-android-studio-3-0/46999705 – Zon May 30 '18 at 11:02
  • I've never had the chance to try this instant run, because for some weird reason it doesn't work when you have more than one process on the app. Maybe it already changed, but I should try again, but I will have to wait since this bug. – AXSM Jun 22 '18 at 21:57
  • Today was the release of android studio 3.2 and I think they did not fix it? Has anyone had a similar experience? – TheOddCoder Sep 25 '18 at 06:06
  • Android Studio 3.2 brought up some other small problems for me but solved this one - deploying the app now with instantrun – Martin Eckleben Sep 25 '18 at 08:24
  • After update Android Studio 3.2 still, face this issue Failed to find byte code for android/service/autofill/AutofillService – Nikhil Sep 25 '18 at 12:45
24

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:

  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

Veer
  • 1,373
  • 1
  • 12
  • 27
  • thanks you, Google already release AS 3.1.1 in stable channel which seem to fix this problem. But cause another problem: https://stackoverflow.com/questions/49770112/execution-failed-for-task-apptransformclasseswithandroidgradleclassshrinkerfo – nhoxbypass Apr 18 '18 at 02:56
11

Disabling Instant Run worked for me

Lagix
  • 139
  • 9
  • 1
    It sure does work, but it's barely an answer to question: why can't I use instant run? – jujka Aug 23 '18 at 09:39
3

if you get unexpected/weird/stupid errors like this it's most probably because of

Instant run

disable it and try again

Ege Kuzubasioglu
  • 5,991
  • 12
  • 49
  • 85
1

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'
    }
0xAliHn
  • 18,390
  • 23
  • 91
  • 111
1

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.

Adolf Dsilva
  • 13,092
  • 8
  • 34
  • 45
0

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.

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
0

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.

0

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.

HelloCsl
  • 201
  • 2
  • 6