ian*_*ake 150 android android-gradle-plugin firebase-performance android-architecture-navigation android-safe-args
I recently downloaded Android Studio Bumblebee and it helpfully asked whether I wanted to upgrade to Android Gradle Plugin 7.1.0, the version that shipped alongside Android Studio Bumblebee.
After upgrading, I get a build error:
Unable to load class 'com.android.build.api.extension.AndroidComponentsExtension'.
This is an unexpected error. Please file a bug containing the idea.log file.
Run Code Online (Sandbox Code Playgroud)
And looking at the idea.log file, I see:
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
Run Code Online (Sandbox Code Playgroud)
Which means I can't run my app and I need to downgrade the AGP 7.0 to get things working again. How do I fix this and upgrade to Android Gradle Plugin 7.1.0?
ian*_*ake 185
Updating Navigation Safe Args
These lines are the important ones to look at:
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)
Run Code Online (Sandbox Code Playgroud)
This indicates that the error is coming from the Navigation Safe Args plugin.
As per the 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.
As Navigation 2.4.1 is now available, you can upgrade to that version of Navigation to gain the fix:
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"
}
Run Code Online (Sandbox Code Playgroud)
Note that you should always use the same version of the Navigation library as the Safe Args plugin (i.e., your app should also use Navigation 2.4.1): you should not try to use the Navigation 2.4.1+ Safe Args plugin with an earlier version of Navigation (such as 2.3.5).
Note on Firebase Perf Plugin
Note that you might see this same error when you are using:
classpath "com.google.firebase:perf-plugin:1.4.0"
Run Code Online (Sandbox Code Playgroud)
With an idea.log of that states:
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)
Run Code Online (Sandbox Code Playgroud)
As per the Firebase Perf Plugin 1.4.1 Release Notes:
Migrated away from the deprecated Android Gradle plugin APIs.
So you should upgrade to 1.4.1:
classpath "com.google.firebase:perf-plugin:1.4.1"
Run Code Online (Sandbox Code Playgroud)
Yur*_*yac 16
就我而言,问题出在刀柄版本上。我已经更新到最后一次2.40.5并且可以工作了。
如果您的项目中没有hilt依赖项,那么找到在 gradle 同步期间引发异常的库的最佳方法是检查idea.log文件。
并找到类似的东西。
Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
at dagger.hilt.android.plugin.HiltGradlePlugin.configureBytecodeTransformASM(HiltGradlePlugin.kt:257)
Run Code Online (Sandbox Code Playgroud)
祝你编码顺利:)
Dav*_*uel 13
更新:该问题现已在AGP 7.1.2中修复。
以下是一些更新:
- AGP
v7.2.0-beta01已于上周推出,并将与最新的性能插件一起使用v1.4.1。- AGP
v7.2 RC1预计于3月1日发布,AGPv7.2决赛预计于3月9日举行。与此同时,以下是一些值得尝试的解决方法:
- 将 perf 插件
v1.3.5与 AGP 一起使用v6.8.3。Perf 插件v1.3.5及以下与 AGP 不兼容v7.0.0+;为了让 perf 插件与 AGP 兼容v7.0.0+,我们必须使用新的转换 API,这会导致构建失败,即使 perf 插件META-INF/从检测中过滤掉目录中的类,AGP 仍然会尝试访问该类来收集有关它的信息。然而,AGP 正在致力于对此进行更永久的修复,我们将可以选择完全过滤掉失败的类。- 等到 3 月 9 日集成最新的 perf 插件版本和 AGP。
- 尝试使用最新性能插件版本的 AGP 测试版,并在 3 月 9 日后转向生产版本。
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.lambda$apply$0(DefaultScriptPluginFactory.java:133)
at ...
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)
at org.gradle.api.internal.plugins.DefaultPluginManager$2.execute(DefaultPluginManager.java:258)
at ...
Run Code Online (Sandbox Code Playgroud)
你可以做这件事。非常适合我
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id "com.google.dagger.hilt.android" version '2.41' apply false
id 'androidx.navigation.safeargs.kotlin' version '2.4.0' apply false // use this one
// classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0" (will not work now)
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
56934 次 |
| 最近记录: |