1. 程式人生 > >Uninitialized object exists on backward branch 70 原因及解決辦法

Uninitialized object exists on backward branch 70 原因及解決辦法

本文出自: https://tianshimanbu.com/more/Uninitialized-object-exists-on-backward-branch-70.html

升級Android Stadio 3.1 後的一波三折

前面文章介紹了很多升級Android Stadio 3.1後帶來的問題及解決辦法

以上這些文章都是為了解決IDE升級後帶來的問題的所有記錄,但是就在博主的工程可以run起來以後(即

IDE打debug版本直接連結到真機上除錯沒有發現任何問題),但再打release版本的時候卻出現了一個刺手的問題。問題的詳情如下:

 

即:使用IDE直接執行可以起來沒有任何問題,但是使用Gradle打Release版本的時候卻報錯。

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not generate a proxy class for class com.android.build.gradle.tasks.BuildArtifactReportTask.

what???!!!以上異常真的是沒有一點點防備,沒有一點點的猶豫就報了,再沒有更多可以尋跡的資訊。接下來在Gradle後面加上--stacktrace 來跟蹤更多的過程資訊:

command-line: gradle build --stacktrace

順利的在編譯控制檯中爆出更多資訊(文末貼出全部的資訊),最有用的當然是以下這一段:

Uninitialized object exists on backward branch 70
Exception Details:
  Location:
    com/android/build/gradle/tasks/BuildArtifactReportTask.newArtifact(Lcom/android/build/api/artifact/BuildableArtifact;)Lcom/android/build/gradle/tasks/BuildArtifactReportTask$BuildableArtifactData; @119: goto
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: bb00 f459 2bb9 0139 0100 c000 6b2b b901
    0000010: 3d01 0001 b901 4302 0059 1301 45b8 0148
    0000020: c000 374d 3a0d 3a0c 3a0b 2c4e bb00 6859
    0000030: 2c10 0ab8 003d b700 69c0 006b 3a04 2db9
    0000040: 0054 0100 3a05 1905 b900 5a01 0099 002d
    0000050: 1905 b900 5e01 003a 0619 0419 06c0 014a
    0000060: 3a07 3a0e 1907 b901 4d01 003a 0f19 0e19
    0000070: 0fb9 0075 0200 57a7 ffcf 1904 c000 773a
    0000080: 0e19 0b19 0c19 0d19 0eb7 0150 b0       
  Stackmap Table:
    full_frame(@70,{Object[#2],Object[#109],Object[#55],Object[#55],Object[#107],Object[#86],Top,Top,Top,Top,Top,Uninitialized[#0],Uninitialized[#0],Object[#107]},{})
    same_frame(@122)

分析和解決辦法

其實幾乎沒有什麼有效的資訊,但是關鍵字Bytecode表明和JDK有關,這裡還在編譯階段,所以應該是引用的JDK的版本有問題。

我升級了一下JDK的版本,仍然不行。通過命令列env檢視JAVA_HOME的位置沒有看出來錯誤。

不過,博主依稀記得,Android Stadio 引用的JDK是它內建的,路徑在/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home,而系統環境中的JDK路徑是:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home

顯然,二者引用的JDK路徑不一樣,也就是能夠解釋為何IDE可以執行起來,而Gradle打版本的時候卻報錯。

原因:

  • IDE run起來的時候,引用了Android Stadio 3.1 內建的JDK,路徑為:/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home
  • Gradle build的時候,引用了系統環境的JDK,即JAVA_HOME中定義的/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home

英文描述叫做:system exists different jdk ,IDE depend on inner JDK,gradle depend on env jdk .

解決辦法

知道了原因,解決起來很容易,辦法有兩個:

  • 1.直接將JAVE_HOME設定為可用的一個,這裡可用的是:/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home(我的是mac電腦,具體路徑請參考自己電腦上的,Android Stadio->project structure->sdk location ->jdk location)

  • 2.由於考慮到以後系統環境中的JDK升級可用,而第一個辦法是臨時的解決方式,只要解決在Gradle build的時候ok就可以。所以可以寫一個打包指令碼,在Gradle build (或者相關打包命令)之前,通過export 指令把JAVE_HOME的值臨時改變一下,即可以達到打包的目的,又不會更改系統的JDK路徑。指令碼示例:

export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home
echo "start gradle....."
gradle clean assembleRelease
echo "gradle end!!!"

至此,Uninitialized object exists on backward branch 70的原因及解決辦法已經給出,希望對各位有幫助。

===============================完整的異常日誌==============================

完整異常日誌,沒有興趣的可以忽略。

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not generate a proxy class for class com.android.build.gradle.tasks.BuildArtifactReportTask.

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

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':app'.
        at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:94)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:89)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:70)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.access$100(LifecycleProjectEvaluator.java:34)
        at org.gradle.configuration.project.LifecycleProjectEvaluator$ConfigureProject.run(LifecycleProjectEvaluator.java:110)
        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.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:50)
        at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:667)
        at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:136)
        at org.gradle.execution.TaskPathProjectEvaluator.configure(TaskPathProjectEvaluator.java:35)
        at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:62)
        at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:38)
        at org.gradle.initialization.DefaultGradleLauncher$ConfigureBuild.run(DefaultGradleLauncher.java:261)
        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.initialization.DefaultGradleLauncher.configureBuild(DefaultGradleLauncher.java:173)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:132)
        at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:115)
        at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:78)
        at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:75)
        at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:152)
        at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:100)
        at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:75)
        at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
        at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
        at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$1.run(RunAsBuildOperationBuildActionRunner.java:43)
        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.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40)
        at org.gradle.tooling.internal.provider.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:51)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:49)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:32)
        at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:39)
        at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:25)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:80)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:53)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:57)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:32)
        at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
        at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
        at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
        at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
        at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:64)
        at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:29)
        at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:59)
        at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:44)
        at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:45)
        at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:30)
        at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
        at org.gradle.util.Swapper.swap(Swapper.java:38)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:62)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
        at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:295)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.api.GradleException: Could not generate a proxy class for class com.android.build.gradle.tasks.BuildArtifactReportTask.
        at org.gradle.api.internal.AbstractClassGenerator.generateUnderLock(AbstractClassGenerator.java:224)
        at org.gradle.api.internal.AbstractClassGenerator.generate(AbstractClassGenerator.java:80)
        at org.gradle.api.internal.project.taskfactory.TaskFactory.create(TaskFactory.java:113)
        at org.gradle.api.internal.project.taskfactory.TaskFactory.create(TaskFactory.java:40)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory.create(AnnotationProcessingTaskFactory.java:49)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory.create(AnnotationProcessingTaskFactory.java:30)
        at org.gradle.api.internal.tasks.DefaultTaskContainer$TaskInstantiator.create(DefaultTaskContainer.java:304)
        at org.gradle.api.internal.tasks.DefaultTaskContainer$TaskInstantiator.create(DefaultTaskContainer.java:292)
        at org.gradle.api.internal.tasks.DefaultTaskContainer.create(DefaultTaskContainer.java:119)
        at org.gradle.api.internal.tasks.DefaultTaskContainer.create(DefaultTaskContainer.java:150)
        at com.android.build.gradle.internal.TaskFactoryImpl.create(TaskFactoryImpl.kt:50)
        at com.android.build.gradle.internal.ApplicationTaskManager.createTasksForVariantScope(ApplicationTaskManager.java:115)
        at com.android.build.gradle.internal.VariantManager.createTasksForVariantData(VariantManager.java:530)
        at com.android.build.gradle.internal.VariantManager.lambda$createAndroidTasks$1(VariantManager.java:352)
        at com.android.build.gradle.internal.VariantManager$$Lambda$150/436108481.call(Unknown Source)
        at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:81)
        at com.android.build.gradle.internal.VariantManager.createAndroidTasks(VariantManager.java:348)
        at com.android.build.gradle.BasePlugin.lambda$createAndroidTasks$6(BasePlugin.java:749)
        at com.android.build.gradle.BasePlugin$$Lambda$108/828734042.call(Unknown Source)
        at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:81)
        at com.android.build.gradle.BasePlugin.createAndroidTasks(BasePlugin.java:744)
        at com.android.build.gradle.BasePlugin.lambda$null$4(BasePlugin.java:650)
        at com.android.build.gradle.BasePlugin$$Lambda$84/872580635.call(Unknown Source)
        at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:81)
        at com.android.build.gradle.BasePlugin.lambda$createTasks$5(BasePlugin.java:646)
        at com.android.build.gradle.BasePlugin$$Lambda$83/527813523.execute(Unknown Source)
        at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:91)
        at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:80)
        at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:42)
        at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:230)
        at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:149)
        at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:58)
        at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:324)
        at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:234)
        at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:140)
        at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:37)
        at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
        at com.sun.proxy.$Proxy24.afterEvaluate(Unknown Source)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:76)
        ... 81 more
Caused by: java.lang.VerifyError: Uninitialized object exists on backward branch 70
Exception Details:
  Location:
    com/android/build/gradle/tasks/BuildArtifactReportTask.newArtifact(Lcom/android/build/api/artifact/BuildableArtifact;)Lcom/android/build/gradle/tasks/BuildArtifactReportTask$BuildableArtifactData; @119: goto
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: bb00 f459 2bb9 0139 0100 c000 6b2b b901
    0000010: 3d01 0001 b901 4302 0059 1301 45b8 0148
    0000020: c000 374d 3a0d 3a0c 3a0b 2c4e bb00 6859
    0000030: 2c10 0ab8 003d b700 69c0 006b 3a04 2db9
    0000040: 0054 0100 3a05 1905 b900 5a01 0099 002d
    0000050: 1905 b900 5e01 003a 0619 0419 06c0 014a
    0000060: 3a07 3a0e 1907 b901 4d01 003a 0f19 0e19
    0000070: 0fb9 0075 0200 57a7 ffcf 1904 c000 773a
    0000080: 0e19 0b19 0c19 0d19 0eb7 0150 b0       
  Stackmap Table:
    full_frame(@70,{Object[#2],Object[#109],Object[#55],Object[#55],Object[#107],Object[#86],Top,Top,Top,Top,Top,Uninitialized[#0],Uninitialized[#0],Object[#107]},{})
    same_frame(@122)

        at org.gradle.internal.reflect.ClassInspector.inspectClass(ClassInspector.java:72)
        at org.gradle.internal.reflect.ClassInspector.visitGraph(ClassInspector.java:56)
        at org.gradle.internal.reflect.ClassInspector.inspect(ClassInspector.java:36)
        at org.gradle.api.internal.AbstractClassGenerator.inspectType(AbstractClassGenerator.java:284)
        at org.gradle.api.internal.AbstractClassGenerator.inspectType(AbstractClassGenerator.java:239)
        at org.gradle.api.internal.AbstractClassGenerator.generateUnderLock(AbstractClassGenerator.java:111)
        ... 119 more


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