gpt4 book ai didi

android - 升级 Android Gradle 插件 7.1 后无法加载类 AndroidComponentsExtension

转载 作者:行者123 更新时间:2023-12-04 23:35:36 25 4
gpt4 key购买 nike

我最近下载了Android Studio Bumblebee它询问了我是否想升级到 Android Gradle Plugin 7.1.0,这是与 Android Studio Bumblebee 一起发布的版本,这很有帮助。
升级后,我得到一个构建错误:

Unable to load class 'com.android.build.api.extension.AndroidComponentsExtension'.

This is an unexpected error. Please file a bug containing the idea.log file.
看着 idea.log文件,我看到:
A problem occurred evaluating project ':main'.
at org.gradle.initialization.exception.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:103)
...
Caused by: org.gradle.api.GradleScriptException: A problem occurred evaluating project ':main'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
...
Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:73)
at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:42)
...
Caused by: java.lang.ClassNotFoundException: com.android.build.api.extension.AndroidComponentsExtension
这意味着我无法运行我的应用程序,我需要降级 AGP 7.0 才能让一切恢复正常。如何解决此问题并升级到 Android Gradle Plugin 7.1.0?

最佳答案

更新导航安全参数
这些行是要查看的重要行:

Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:73)
at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:42)
这表明错误来自 Navigation Safe Args plugin
根据 Android Gradle Plugin 7.1.0 release notes :

AGP APIs that the Navigation Safe Args Gradle plugin depend on have been removed. AGP 7.1 does not work with Navigation Safe Args versions 2.4.0-rc1 or 2.4.0, but will work with versions 2.5.0-alpha01 and 2.4.1. In the meantime, as a workaround, you can use AGP 7.1 with a snapshot build of Navigation Safe Args, Navigation 2.5.0-SNAPSHOT. To use the snapshot build, follow the snapshot instructions with build id #8054565.


由于 Navigation 2.4.1 现在可用,您可以升级到该版本的 Navigation 以获得修复:

Backported from Navigation 2.5.0-alpha01: Safe Args now depends on Android Gradle Plugin version 7.0.4. This means that Navigation Safe Args will no longer be compatible with Android Studio versions prior to 7.0, but is now compatible with Android Gradle Plugin 7.1.0 and higher.

dependencies {
classpath 'com.android.tools.build:gradle:7.1.0'

// Update this line to use 2.4.1
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.1"
}
请注意,您应始终使用与 Safe Args 插件相同版本的 Navigation 库(即,您的应用程序也应使用 Navigation 2.4.1):您不应尝试将 Navigation 2.4.1+ Safe Args 插件与早期版本一起使用Navigation 的版本(例如 2.3.5)。
Firebase Perf 插件注意事项
请注意,您在使用时可能会看到同样的错误:
classpath "com.google.firebase:perf-plugin:1.4.0"
使用 idea.log 的状态:
Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
at com.google.firebase.perf.plugin.FirebasePerfClassVisitorFactory.registerForProject(FirebasePerfClassVisitorFactory.java:54)
at com.google.firebase.perf.plugin.FirebasePerfPlugin.perform(FirebasePerfPlugin.java:145)
at com.google.firebase.perf.plugin.FirebasePerfPlugin.lambda$apply$0(FirebasePerfPlugin.java:107)
根据 Firebase Perf Plugin 1.4.1 Release Notes :

Migrated away from the deprecated Android Gradle plugin APIs.


所以你应该升级到 1.4.1:
classpath "com.google.firebase:perf-plugin:1.4.1"

关于android - 升级 Android Gradle 插件 7.1 后无法加载类 AndroidComponentsExtension,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70857476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com