Android Studio (3.2.1) Instant Run 不适用于 Jacoco 0.8.2?
Posted
技术标签:
【中文标题】Android Studio (3.2.1) Instant Run 不适用于 Jacoco 0.8.2?【英文标题】:Android Studio (3.2.1) Instant Run doesn't work with Jacoco 0.8.2? 【发布时间】:2019-04-03 00:12:04 【问题描述】:我使用 android Studio 3.2.1 创建了一个简单的 Empty Activity 项目 (Java)。使用 Instant Run 可以正常编译。
但是,当我将 Jacoco 0.8.2 添加到类路径时
dependencies
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'org.jacoco:org.jacoco.core:0.8.2' //<--Added this
编译的时候报错
:app:transformClassesWithInstantRunForDebug 134 ms
禁用即时运行就可以了。这是 Jacoco 或 Android sdk 中的错误吗?
已更新错误说明
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithInstantRunForDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
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:256)
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:249)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
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:663)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597)
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: java.lang.RuntimeException: com.android.build.api.transform.TransformException: java.lang.IllegalStateException: java.lang.IllegalStateException
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:230)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
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:50)
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:124)
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:113)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95)
... 33 more
Caused by: com.android.build.api.transform.TransformException: java.lang.IllegalStateException: java.lang.IllegalStateException
at com.android.build.gradle.internal.transforms.InstantRunTransform.doTransform(InstantRunTransform.java:320)
at com.android.build.gradle.internal.transforms.InstantRunTransform.transform(InstantRunTransform.java:186)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:239)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:235)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
... 49 more
Caused by: java.lang.IllegalStateException: java.lang.IllegalStateException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:593)
at java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:677)
at java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:720)
at com.android.ide.common.internal.WaitableExecutor.waitForTasksWithQuickFail(WaitableExecutor.java:146)
at com.android.build.gradle.internal.transforms.InstantRunTransform.doTransform(InstantRunTransform.java:315)
... 53 more
Caused by: java.lang.IllegalStateException
at org.objectweb.asm.tree.analysis.BasicInterpreter.<init>(BasicInterpreter.java:66)
at com.android.build.gradle.internal.incremental.ConstructorBuilder$1.<init>(ConstructorBuilder.java:127)
at com.android.build.gradle.internal.incremental.ConstructorBuilder.build(ConstructorBuilder.java:127)
at com.android.build.gradle.internal.incremental.IncrementalSupportVisitor.visitMethod(IncrementalSupportVisitor.java:223)
at org.objectweb.asm.ClassVisitor.visitMethod(ClassVisitor.java:327)
at org.objectweb.asm.commons.SerialVersionUIDAdder.visitMethod(SerialVersionUIDAdder.java:236)
at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:686)
at org.objectweb.asm.tree.ClassNode.accept(ClassNode.java:436)
at com.android.build.gradle.internal.incremental.IncrementalVisitor.instrumentClass(IncrementalVisitor.java:365)
at com.android.build.gradle.internal.transforms.InstantRunTransform.transformToClasses2Format(InstantRunTransform.java:414)
at com.android.build.gradle.internal.transforms.InstantRunTransform.lambda$doTransform$4(InstantRunTransform.java:276)
at com.android.build.gradle.internal.transforms.InstantRunTransform.lambda$null$5(InstantRunTransform.java:305)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
【问题讨论】:
向 Jacoco github.com/jacoco/jacoco/issues/779提出的问题 这是 Gradle 任务的名称,而不是错误描述;将其添加到类路径中不足以使其工作。 根据issuetracker.google.com/issues/118709917向谷歌发布文件 【参考方案1】:作为一种可能的解决方法,您可以尝试使用依赖 ASM 6.0 的 JaCoCo 0.8.1
。
【讨论】:
【参考方案2】:在https://github.com/jacoco/jacoco/issues/779#issuecomment-434281431 引用我的回答:
如您所见 - 异常源自
com.android.build.gradle.internal
:Caused by: java.lang.IllegalStateException at org.objectweb.asm.tree.analysis.BasicInterpreter.<init>(BasicInterpreter.java:66) at com.android.build.gradle.internal.incremental.ConstructorBuilder$1.<init>(ConstructorBuilder.java:127) at com.android.build.gradle.internal.incremental.ConstructorBuilder.build(ConstructorBuilder.java:127) at com.android.build.gradle.internal.incremental.IncrementalSupportVisitor.visitMethod(IncrementalSupportVisitor.java:223) at org.objectweb.asm.ClassVisitor.visitMethod(ClassVisitor.java:327) at org.objectweb.asm.commons.SerialVersionUIDAdder.visitMethod(SerialVersionUIDAdder.java:236) at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:686) at org.objectweb.asm.tree.ClassNode.accept(ClassNode.java:436) at com.android.build.gradle.internal.incremental.IncrementalVisitor.instrumentClass(IncrementalVisitor.java:365) at com.android.build.gradle.internal.transforms.InstantRunTransform.transformToClasses2Format(InstantRunTransform.java:414) at com.android.build.gradle.internal.transforms.InstantRunTransform.lambda$doTransform$4(InstantRunTransform.java:276) at com.android.build.gradle.internal.transforms.InstantRunTransform.lambda$null$5(InstantRunTransform.java:305)
代码
com.android.build.gradle.internal.incremental.ConstructorBuilder.build
这会导致异常ConstructorBuilder.java:127
:BasicInterpreter interpreter = new BasicInterpreter()
根据构造函数的Javadoc,这是不正确的
org.objectweb.asm.tree.analysis.BasicInterpreter
抛出 例外在BasicInterpreter.java:66
:/** * Constructs a new @link BasicInterpreter for the latest ASM API version. <i>Subclasses must * not use this constructor</i>. Instead, they must use the @link #BasicInterpreter(int) * version. */ public BasicInterpreter() super(ASM6); if (getClass() != BasicInterpreter.class) throw new IllegalStateException();
显然这应该报告给 Android SDK 的开发者 - https://developer.android.com/studio/report-bugs.html
有人可能想知道为什么没有最后一行就不会发生异常
dependencies classpath 'com.android.tools.build:gradle:3.2.1' classpath 'org.jacoco:org.jacoco.core:0.8.2'
而且原因类似 https://github.com/jacoco/jacoco/issues/639#issuecomment-355424756 - 类路径中有多个 ASM 版本:
JaCoCo 0.8.2 需要 ASM 6.2.1 和org.jacoco:org.jacoco.core:0.8.2
正确声明依赖于 ASM exception was added in ASM 6.1com.android.build.gradle.internal.incremental.ConstructorBuilder
很可能是开发/使用旧版本的 ASM为避免此类类路径问题,Android SDK 的开发者可以 重新考虑他们执行 JaCoCo 的方式,例如使用专用的 类加载器。
作为一种可能的解决方法,您可以尝试使用 JaCoCo 0.8.1,这取决于 在 ASM 6.0 上
【讨论】:
谢谢。按照issuetracker.google.com/issues/118709917 向谷歌发出文件 @Elye 如果答案有帮助/正确,请考虑投票/将其标记为已接受。以上是关于Android Studio (3.2.1) Instant Run 不适用于 Jacoco 0.8.2?的主要内容,如果未能解决你的问题,请参考以下文章
Flutter android studio in mac 显示 Please configure Android SDK in Logcat
安装Android studio出现'tools.jar' seems to be not in Android Studio classpath......的解决方法
Android Studio sdk use in unity
Android Studio 3.2.1:transformDexArchiveWithExternalLibsDexMergerForDebug 失败