R8 从 AndroidStudio 中抛出 NullPointerException,但不是从命令行通过 gradlew

Posted

技术标签:

【中文标题】R8 从 AndroidStudio 中抛出 NullPointerException,但不是从命令行通过 gradlew【英文标题】:R8 throws NullPointerException from within AndroidStudio, but not from commandline via gradlew 【发布时间】:2020-01-15 21:15:02 【问题描述】:

问题

当我点击 android Studio 中的调试图标时,我从 R8 中得到了这个 NullPointerException。

Executing tasks: [:app:assembleDebug] in project /Users/gary/Developer/Foo/Foo-Android

> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:checkDebugManifest UP-TO-DATE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:mainApkListPersistenceDebug
> Task :app:generateDebugResValues
> Task :app:generateDebugResources
> Task :app:createDebugCompatibleScreenManifests
> Task :app:processDebugManifest
> Task :app:mergeDebugResources
> Task :app:processDebugResources
> Task :app:kaptGenerateStubsDebugKotlin

> Task :app:kaptDebugKotlin
w: [kapt] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (NON_INCREMENTAL).

> Task :app:compileDebugKotlin
w: /Users/gary/Developer/Foo/Foo-Android/app/src/main/java/com/foo/restapis/LoggingInterceptor.kt: (38, 49): 'create(MediaType?, String): ResponseBody' is deprecated. Moved to extension function. Put the 'content' argument first to fix Java
w: /Users/gary/Developer/Foo/Foo-Android/app/src/main/java/com/Foo/screens/player/PlayerActivity.kt: (132, 33): 'getRunningServices(Int): (Mutable)List<ActivityManager.RunningServiceInfo!>!' is deprecated. Deprecated in Java
w: /Users/gary/Developer/Foo/Foo-Android/app/src/main/java/com/foo/service/KKAudioPlayer.kt: (205, 35): 'setNotificationListener(PlayerNotificationManager.NotificationListener!): Unit' is deprecated. Deprecated in Java
w: /Users/gary/Developer/Foo/Foo-Android/app/src/main/java/com/foo/service/KKAudioPlayer.kt: (283, 32): 'ExtractorMediaSource' is deprecated. Deprecated in Java
w: /Users/gary/Developer/Foo/Foo-Android/app/src/main/java/com/foo/service/KKAudioPlayer.kt: (283, 53): 'Factory' is deprecated. Deprecated in Java
w: /Users/gary/Developer/Foo/Foo-Android/app/src/main/java/com/foo/service/KKAudioPlayer.kt: (293, 17): 'ExtractorMediaSource' is deprecated. Deprecated in Java
w: /Users/gary/Developer/Foo/Foo-Android/app/src/main/java/com/foo/service/KKAudioPlayer.kt: (293, 38): 'Factory' is deprecated. Deprecated in Java
w: /Users/gary/Developer/Foo/Foo-Android/app/src/main/java/com/foo/service/KKAudioPlayer.kt: (295, 21): 'ExtractorMediaSource' is deprecated. Deprecated in Java
w: /Users/gary/Developer/Foo/Foo-Android/app/src/main/java/com/foo/service/KKAudioPlayer.kt: (295, 42): 'Factory' is deprecated. Deprecated in Java

> Task :app:mergeDebugShaders
> Task :app:compileDebugShaders
> Task :app:generateDebugAssets
> Task :app:mergeDebugAssets
> Task :app:javaPreCompileDebug
> Task :app:compileDebugJavaWithJavac
> Task :app:compileDebugSources
> Task :app:processDebugJavaRes NO-SOURCE
> Task :app:validateSigningDebug
> Task :app:checkDebugDuplicateClasses
> Task :app:transformClassesWithProfilers-transformForDebug
> Task :app:mergeDebugJavaResource

> Task :app:transformClassesWithDexBuilderForDebug FAILED
org.gradle.workers.WorkerExecutionException: There was a failure while executing work items
    at org.gradle.workers.internal.DefaultWorkerExecutor.workerExecutionException(DefaultWorkerExecutor.java:158)
    at org.gradle.workers.internal.DefaultWorkerExecutor.await(DefaultWorkerExecutor.java:152)
    at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.transform(DexArchiveBuilderTransform.java:424)
    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:106)
    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:103)
    at org.gradle.api.internal.project.taskfactory.IncrementalTaskInputsTaskAction.doExecute(IncrementalTaskInputsTaskAction.java:46)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:41)
    at org.gradle.api.internal.project.taskfactory.AbstractIncrementalTaskAction.execute(AbstractIncrementalTaskAction.java:25)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:28)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$5.run(ExecuteActionsTaskExecuter.java:404)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:393)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:376)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$200(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:213)
    at org.gradle.internal.execution.steps.ExecuteStep.lambda$execute$0(ExecuteStep.java:32)
    at java.util.Optional.map(Optional.java:215)
    at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:32)
    at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:26)
    at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:58)
    at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:35)
    at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:48)
    at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:33)
    at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:39)
    at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:73)
    at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:54)
    at org.gradle.internal.execution.steps.CatchExceptionStep.execute(CatchExceptionStep.java:35)
    at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:51)
    at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:45)
    at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:31)
    at org.gradle.internal.execution.steps.CacheStep.executeWithoutCache(CacheStep.java:201)
    at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:70)
    at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:45)
    at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:49)
    at org.gradle.internal.execution.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:43)
    at org.gradle.internal.execution.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:32)
    at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:38)
    at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:24)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:96)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:89)
    at java.util.Optional.map(Optional.java:215)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:54)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:38)
    at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:77)
    at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:37)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:36)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:26)
    at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:90)
    at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:48)
    at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:33)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:120)
    at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.execute(ResolveBeforeExecutionStateTaskExecuter.java:75)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:108)
    at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionOutputsTaskExecuter.execute(ResolveBeforeExecutionOutputsTaskExecuter.java:67)
    at org.gradle.api.internal.tasks.execution.ResolveAfterPreviousExecutionStateTaskExecuter.execute(ResolveAfterPreviousExecutionStateTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:94)
    at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:95)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:73)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:49)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:49)
    at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:43)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:355)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:336)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:322)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:134)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:129)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:202)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:193)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
    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:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform$DexConversionWorkAction
    at org.gradle.workers.internal.DefaultWorkerExecutor$WorkerExecution.waitForCompletion(DefaultWorkerExecutor.java:285)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:115)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForCompletion(DefaultAsyncWorkTracker.java:87)
    at org.gradle.workers.internal.DefaultWorkerExecutor.await(DefaultWorkerExecutor.java:150)
    ... 100 more
Caused by: org.gradle.tooling.BuildException: Failed to process /Users/gary/Developer/Foo/Foo-Android/app/build/intermediates/transforms/profilers-transform/debug/29.jar
    at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform$DexConversionWorkAction.run(DexArchiveBuilderTransform.java:705)
    at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:39)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.execute(NoIsolationWorkerFactory.java:61)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:55)
    at org.gradle.workers.internal.DefaultWorkerExecutor$1.call(DefaultWorkerExecutor.java:105)
    at org.gradle.workers.internal.DefaultWorkerExecutor$1.call(DefaultWorkerExecutor.java:99)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    ... 6 more
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process /Users/gary/Developer/Foo/Foo-Android/app/build/intermediates/transforms/profilers-transform/debug/29.jar
    at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.launchProcessing(DexArchiveBuilderTransform.java:910)
    at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.access$600(DexArchiveBuilderTransform.java:114)
    at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform$DexConversionWorkAction.run(DexArchiveBuilderTransform.java:697)
    ... 27 more
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.
    at com.android.builder.dexing.D8DexArchiveBuilder.getExceptionToRethrow(D8DexArchiveBuilder.java:124)
    at com.android.builder.dexing.D8DexArchiveBuilder.convert(D8DexArchiveBuilder.java:101)
    at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.launchProcessing(DexArchiveBuilderTransform.java:905)
    ... 29 more
Caused by: java.lang.NullPointerException
    at com.android.tools.r8.ir.conversion.N.b(:988)
    at com.android.tools.r8.ir.conversion.N.buildPrelude(:149)
    at com.android.tools.r8.ir.conversion.IRBuilder.a(:51)
    at com.android.tools.r8.graph.JarCode.a(:16)
    at com.android.tools.r8.graph.JarCode.b(:69)
    at com.android.tools.r8.graph.JarCode.buildIR(:1)
    at com.android.tools.r8.graph.DexEncodedMethod.buildIR(:2)
    at com.android.tools.r8.ir.conversion.IRConverter.b(:215)
    at com.android.tools.r8.ir.conversion.IRConverter.b(:37)
    at com.android.tools.r8.ir.conversion.IRConverter.a(:49)
    at com.android.tools.r8.graph.DexClass.forEachMethod(:2)
    at com.android.tools.r8.ir.conversion.IRConverter.b(:28)
    at com.android.tools.r8.ir.conversion.IRConverter.d(:8)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:125)
    at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:57)
    at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:78)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutorService.execute(MoreExecutors.java:261)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
    at com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:56)
    at com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:36)
    at com.android.tools.r8.ir.conversion.IRConverter.a(:44)
    at com.android.tools.r8.ir.conversion.IRConverter.a(:9)
    at com.android.tools.r8.D8.a(:33)
    at com.android.tools.r8.D8.d(:8)
    at com.android.tools.r8.D8.b(:1)
    at com.android.tools.r8.utils.t.a(:23)
    at com.android.tools.r8.D8.run(:11)
    at com.android.builder.dexing.D8DexArchiveBuilder.convert(D8DexArchiveBuilder.java:99)
    ... 30 more
    Suppressed: java.util.concurrent.ExecutionException: java.lang.NullPointerException
        at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:552)
        at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:513)
        at com.google.common.util.concurrent.FluentFuture$TrustedFuture.get(FluentFuture.java:82)
        at com.android.tools.r8.utils.ThreadUtils.a(:4)
        at com.android.tools.r8.ir.conversion.IRConverter.a(:46)
        ... 37 more
    [CIRCULAR REFERENCE:java.lang.NullPointerException]


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.
> There was a failure while executing work items
   > A failure occurred while executing com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform$DexConversionWorkAction
      > Failed to process /Users/gary/Developer/Foo/Foo-Android/app/build/intermediates/transforms/profilers-transform/debug/29.jar

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 45s
21 actionable tasks: 19 executed, 2 up-to-date

但是……

当我尝试通过从命令行运行 gradlew 来进一步调查时,没有报告错误。

./gradlew :app:assembleDebug

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 16s
29 actionable tasks: 12 executed, 17 up-to-date

所以我不知道如何进行。这是一个商业媒体应用程序,已经通过了 beta 测试,本来应该发布的……但现在这让我受阻了。

到目前为止我尝试过的事情......

    清理并重建 文件 -> 使缓存无效并重新启动 擦除项目 .gradle 和 user/.gradle 缓存,清理并重建 在 gradle.config 中启用MultiDex = true 将 JVM 内存从 2MB 增加到 4MB 重新启动计算机

问题

    如何解决此异常并摆脱困境? 是我的代码还是 R8 错误? 为什么我不能从命令行重现错误? Android Studio 是否在运行带有额外标志的 gradle 时未报告?

版本信息

(在堆栈溢出中归档时,所有内容都应该是最新的)

Android Studio 3.5 Gradle 5.4.1 Android Studio Gradle 插件 3.5.0 Java 1.8 构建工具 28.0.3

build.gradle =

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'


android 
    compileSdkVersion 28
    defaultConfig 
        applicationId "com.foo"
        minSdkVersion 25
        targetSdkVersion 28
        versionCode 16
        versionName "1.0.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        javaCompileOptions 
            annotationProcessorOptions 
                arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
            
        
    

    buildTypes 
        debug 
            buildConfigField "String", 'AUTH_URL', "\"https://debug.foo.com/oauth/\""
            buildConfigField "String", 'BASE_URL', "\"https://debug.foo.com/api/v1/\""
        
        staging 
            buildConfigField "String", 'AUTH_URL', "\"https://staging.foo.com/oauth/\""
            buildConfigField "String", 'BASE_URL', "\"https://staging.foo.com/api/v1/\""
        
        release 
            buildConfigField "String", 'AUTH_URL', "\"https://api.foo.com/oauth/\""
            buildConfigField "String", 'BASE_URL', "\"https://api.foo.com/api/v1/\""

            // enables code shrinking, obfuscation, and optimization
            minifyEnabled true

            // enables resource shrinking
            shrinkResources true

            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        
    
    compileOptions 
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    
    androidExtensions 
        experimental = true
    
    lintOptions 
        disable 'RestrictedApi'
    
    kotlinOptions 
        jvmTarget = '1.8'
    
    kapt 
        useBuildCache = true
    
    packagingOptions 
        exclude 'META-INF/atomicfu.kotlin_module'
    
    buildToolsVersion = '28.0.3'


dependencies 
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.50"
    implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.50"
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0'

    implementation "android.arch.lifecycle:extensions:1.1.1"
    kapt "android.arch.lifecycle:common-java8:1.1.1"

    implementation "android.arch.persistence.room:runtime:1.1.1"
    kapt "android.arch.persistence.room:compiler:1.1.1"
    implementation "android.arch.persistence.room:rxjava2:1.1.1"
    testImplementation "android.arch.persistence.room:testing:1.1.1"

    implementation 'com.google.android.exoplayer:exoplayer-core:2.10.1'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.10.1'

    implementation "androidx.appcompat:appcompat:1.1.0"
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation "androidx.preference:preference:1.1.0"

    // retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.6.1'
    implementation 'com.squareup.retrofit2:converter-moshi:2.6.1'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.1'

    // rxjava
    implementation "io.reactivex.rxjava2:rxjava:2.2.10"
    implementation "io.reactivex.rxjava2:rxandroid:2.1.1"

    implementation 'cz.ackee.rxoauth2:core:2.1.1'
    implementation 'cz.ackee.rxoauth2:retrofit-adapter:2.1.1'


    implementation 'com.squareup.picasso:picasso:2.71828'

    implementation 'com.google.android.material:material:1.0.0'

    implementation 'com.beust:klaxon:5.0.1'

    // test

    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.5.1"

    testImplementation "androidx.test:runner:1.2.0"
    testImplementation 'org.assertj:assertj-core:3.13.2'
    testImplementation "org.junit.jupiter:junit-jupiter-api:5.5.1"
    testImplementation "org.junit.jupiter:junit-jupiter-params:5.5.1"
    testImplementation "io.mockk:mockk:1.9.3"
    testImplementation "com.github.andrzejchm.RESTMock:android:0.4.0"

    androidTestImplementation "androidx.test:runner:1.2.0"
    androidTestImplementation "androidx.test.espresso:espresso-core:3.2.0"

gradle.properties =

org.gradle.jvmargs=-Xmx4096m
kotlin.code.style=official

# migrate to androidX
android.useAndroidX=true
android.enableJetifier=true

【问题讨论】:

第二天重新启动后,发现buildTools可以更新到29.0.2。然后问题就消失了。 即使在更新 buildTools 后也面临同样的问题 【参考方案1】:

遵循commit 38934 中提到的解决方法并禁用高级分析

【讨论】:

【参考方案2】:

由于我无权发表评论,因此发布为答案:

如果您仅在构建到 Lollipop 或 Marshmallow 设备时才看到 R8 Nullpointerexception,那么禁用高级分析对我来说就可以了。

所有功劳归功于安东尼奥姆林!谢谢!

【讨论】:

在这里找到它:运行 -> 编辑配置 -> 分析 -> 启用高级分析【参考方案3】:

我遇到了类似的问题,就我而言,我通过将 java 版本从 15 降级到 11(Android Studio 包中的默认 java)解决了这个问题

希望这些信息可以帮助像我一样遇到同样情况的人?

【讨论】:

以上是关于R8 从 AndroidStudio 中抛出 NullPointerException,但不是从命令行通过 gradlew的主要内容,如果未能解决你的问题,请参考以下文章

调用可以抛出,但错误不能从全局变量初始化器中抛出

如果在“等待”之后抛出,则从任务中抛出的异常被吞下

从变量中抛出异常

从匿名内部类的构造函数中抛出异常

从信号处理程序中抛出异常

使用 Mockito 从模拟中抛出已检查的异常