文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Android Studio升级Gradle Plugin升级导致项目运行失败问题

2023-08-31 20:05

关注

背景&错误

升级Android Studio
旧项目无法运行,奇奇怪怪什么错误都有
例如:

java.lang.IllegalAccessError: class org.gradle.api.internal.tasks.compile.processing.AggregatingProcessingStrategy (in unnamed module @0x390ea9fb) cannot access class com.sun.tools.javac.code.Symbol$ClassSymbol (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.code to unnamed module @0x390ea9fb* Exception is:org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':BaziPaipan_lib:compileDebugJavaWithJavac'.at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:200)at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:263)at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:198)at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:179)at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:109)at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:62)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:77)at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200)at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195)at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:62)at org.gradle.internal.operations.DefaultBuildOperationExecutor.lambda$call$2(DefaultBuildOperationExecutor.java:76)at org.gradle.internal.operations.UnmanagedBuildOperationWrapper.callWithUnmanagedSupport(UnmanagedBuildOperationWrapper.java:54)at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:76)at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:41)at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:372)at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:359)at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:352)at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:338)at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127)at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191)at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182)at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124)at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)Caused by: java.lang.RuntimeException: java.lang.IllegalAccessError: class org.gradle.api.internal.tasks.compile.processing.AggregatingProcessingStrategy (in unnamed module @0x390ea9fb) cannot access class com.sun.tools.javac.code.Symbol$ClassSymbol (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.code to unnamed module @0x390ea9fbat jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(Unknown Source)at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(Unknown Source)

又例如:
在这里插入图片描述

排查解决

初步排查判断是旧项目Gradle版本问题导致。因为最近创建的项目,升级AS之后无影响,只有旧项目跑不起来。

查阅资料发现,随着AS gradle插件版本的升级,项目中gradle plugin版本、gradle版本、jdk版本等均需要配合一起升级,否则编译不过。比如类似这种报错提示:

build.gradle 中配置的gradle版本太低:

Unsupported Java. Your build is currently configured to use Java 17.0.6 and Gradle 6.7.1.

gradle.properties中配置的gradle版本很高,builde.gradle中配置没有匹配:

Could not resolve all dependencies for configuration ':classpath'.   > Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository 'maven5(http://mvn.mob.com/android)' to redirect to a secure protocol (like HTTPS) or allow insecure protocols. See https://docs.gradle.org/7.5.1/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details. 

gradle.properties中配置的版本太低,匹配不上AS版本或者gradle版本

Unsupported Gradle. The project uses Gradle 2.14.1 which is incompatible with Android Studio 2022.2.

其实以上错误,基本上都是版本不匹配导致,那么,匹配上基本就能解决了。

从官网整理了一份各版本对应表:

AGP版本(build.gradle中)Gradle最低版本(gradle.properties中)最低JDK版本(项目配置)SDK Build Tools
8.18.01730.0.3
8.08.01730.0.3
7.47.51130.0.3
7.37.41130.0.3
7.27.3.31130.0.3
7.17.21130.0.3
7.07.0.21130.0.2
4.2.0+6.7.11.730.0.2
4.1.0+6.5+1.729.0.2
4.0.0+6.1.1+1.729.0.2
3.6.0 - 3.6.45.6.4+1.728.0.3
3.5.0 - 3.5.45.4.1+1.728.0.3
3.4.0 - 3.4.35.1.1+1.728.0.3
Android Studio 版本所需 AGP 版本
Giraffe | 2022.3.13.2-8.1
Flamingo | 2022.2.13.2-8.0
Electric Eel | 2022.1.13.2-7.4
Dolphin | 2021.3.13.2-7.3
Chipmunk | 2021.2.13.2-7.2
Bumblebee | 2021.1.13.2-7.1
Arctic Fox | 2020.3.13.1-7.0

方案

修改项目配置,对应上版本,很多老项目还在4.x版本,所以不兼容报错,一般升级7.0+就能解决,这也是谷歌倒推着我们开发者们往上升级,旧版的一些api慢慢都会废弃掉。

从4.x升级至7.0+的话,配置改动会大一点,主要是依赖仓库的配置、上传发布maven等日常配置,教程网上一堆,自行搜索即可。

来源地址:https://blog.csdn.net/lizebin_bin/article/details/130228054

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     807人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     351人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     314人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     433人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     221人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-移动开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯