avatarFlutter Developer

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

3095

Abstract

s="hljs-selector-class">.android</span><span class="hljs-selector-class">.build</span><span class="hljs-selector-class">.api</span><span class="hljs-selector-class">.extension</span>.AndroidComponentsExtension</pre></div><h1 id="e6e3">Solved:</h1><p id="5722"><b>Updating Navigation Safe Args</b></p><p id="e005">These lines are the important ones to look at:</p><div id="3319"><pre>Caused by: java<span class="hljs-selector-class">.lang</span><span class="hljs-selector-class">.NoClassDefFoundError</span>: com/android/build/api/extension/AndroidComponentsExtension at androidx<span class="hljs-selector-class">.navigation</span><span class="hljs-selector-class">.safeargs</span><span class="hljs-selector-class">.gradle</span><span class="hljs-selector-class">.SafeArgsPlugin</span><span class="hljs-selector-class">.apply</span>(SafeArgsPlugin<span class="hljs-selector-class">.kt</span>:<span class="hljs-number">73</span>) at androidx<span class="hljs-selector-class">.navigation</span><span class="hljs-selector-class">.safeargs</span><span class="hljs-selector-class">.gradle</span><span class="hljs-selector-class">.SafeArgsPlugin</span><span class="hljs-selector-class">.apply</span>(SafeArgsPlugin<span class="hljs-selector-class">.kt</span>:<span class="hljs-number">42</span>)</pre></div><p id="fe8b">This indicates that the error is coming from the <a href="https://developer.android.com/guide/navigation/navigation-pass-data#Safe-args">Navigation Safe Args plugin</a>.</p><p id="0930">As per the <a href="https://developer.android.com/studio/releases/gradle-plugin#navigation_safe_args_compatibility">Android Gradle Plugin 7.1.0 release notes</a>:</p><blockquote id="dc31"><p><i>AGP APIs that the Navigation Safe Args Gradle plugin depend on have been removed. <b>AGP 7.1 does not work with Navigation Safe Args versions 2.4.0-rc1 or 2.4.0</b>, 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 <a href="https://androidx.dev/">snapshot instructions</a> with build id #8054565.</i></p></blockquote><p id="1f19">While Navigation 2.4.1 is not out yet, <a href="https://developer.android.com/jetpack/androidx/releases/navigation#2.5.0-alpha01">Navigation <code>2.5.0-alph</code>a01</a> <b>is</b> available, which allows you to use Safe Args 2.5.0-alpha01 to fix this incompatibility:</p><div id="c440"><pre><span class="hljs-attribute">dependencies</span> { <span class="hljs-attribute">classpath</span> 'com.android.tools.build:gradle:<span class="hljs-number">7</span>.<span class="hljs-number">1</span>.<span class="hljs-number">0</span>'</pre></div><div id="332e"><pre> <span class="hljs-comment">// Update this line to use 2.5.0-alpha01</span> <span class="hljs-keyword">classpath</span> <span class="hljs-string">"androidx.navigation:navigation-safe-args-gradle-plugin:2.5.0-alpha01"</span> }</pre></div><p id="5863">While technically you should always use the same version of the Navigation

Options

library as the Safe Args plugin (i.e., your app should also use Navigation 2.5.0-alpha01, in this case, using a <a href="https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0">Navigation <code>2.</code>4.0 stable</a> and updating only the Safe Args Plugin to use 2.5.0-alpha01 is enough to fix the issue and let you continue to use AGP 7.1.0.</p><p id="43f4"><b>Note on Firebase Perf Plugin</b></p><p id="6b93">Note that you might see this same error when you are using:</p><div id="db23"><pre><span class="hljs-keyword">classpath</span> <span class="hljs-string">"com.google.firebase:perf-plugin:1.4.0"</span></pre></div><p id="16d0">With an <code>idea.log</code> of that states:</p><div id="2e5d"><pre>Caused by: java<span class="hljs-selector-class">.lang</span><span class="hljs-selector-class">.NoClassDefFoundError</span>: com/android/build/api/extension/AndroidComponentsExtension at com<span class="hljs-selector-class">.google</span><span class="hljs-selector-class">.firebase</span><span class="hljs-selector-class">.perf</span><span class="hljs-selector-class">.plugin</span><span class="hljs-selector-class">.FirebasePerfClassVisitorFactory</span><span class="hljs-selector-class">.registerForProject</span>(FirebasePerfClassVisitorFactory<span class="hljs-selector-class">.java</span>:<span class="hljs-number">54</span>) at com<span class="hljs-selector-class">.google</span><span class="hljs-selector-class">.firebase</span><span class="hljs-selector-class">.perf</span><span class="hljs-selector-class">.plugin</span><span class="hljs-selector-class">.FirebasePerfPlugin</span><span class="hljs-selector-class">.perform</span>(FirebasePerfPlugin<span class="hljs-selector-class">.java</span>:<span class="hljs-number">145</span>) at com<span class="hljs-selector-class">.google</span><span class="hljs-selector-class">.firebase</span><span class="hljs-selector-class">.perf</span><span class="hljs-selector-class">.plugin</span><span class="hljs-selector-class">.FirebasePerfPlugin</span>.lambda<span class="hljs-variable">apply</span><span class="hljs-number">0</span>(FirebasePerfPlugin<span class="hljs-selector-class">.java</span>:<span class="hljs-number">107</span>)</pre></div><p id="8949">As per the <a href="https://firebase.google.com/support/release-notes/android#performance_gradle_plugin_v1-4-1">Firebase Perf Plugin 1.4.1 Release Notes</a>:</p><blockquote id="7e92"><p><i>Migrated away from the deprecated Android Gradle plugin APIs.</i></p></blockquote><p id="86f0">So you should upgrade to 1.4.1:</p><div id="545e"><pre><span class="hljs-keyword">classpath</span> <span class="hljs-string">"com.google.firebase:perf-plugin:1.4.1"</span></pre></div><p id="66a2">Hope this helped 🙏</p><p id="c9dd">Support me by <a href="https://flutter-developer.medium.com/membership">becoming a Medium member</a> 🥳, and get access to unique programming articles that will enhance you skills.</p><p id="e25d"><a href="https://flutter-developer.medium.com/membership">Become a Medium member</a> — 🖖 Live long and prosper 🖖</p></article></body>

Solved — Unable to load class AndroidComponentsExtension after upgrading the Android Gradle Plugin 7.1

Error after downloading downloaded Android Studio Bumblebee

After upgrading:

Unable to load class 'com.android.build.api.extension.AndroidComponentsExtension'.
This is an unexpected error. Please file a bug containing the idea.log file. 

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

Solved:

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)

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.

While Navigation 2.4.1 is not out yet, Navigation 2.5.0-alpha01 is available, which allows you to use Safe Args 2.5.0-alpha01 to fix this incompatibility:

dependencies {
    classpath 'com.android.tools.build:gradle:7.1.0'
    // Update this line to use 2.5.0-alpha01
    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.5.0-alpha01"
}

While technically 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.5.0-alpha01, in this case, using a Navigation 2.4.0 stable and updating only the Safe Args Plugin to use 2.5.0-alpha01 is enough to fix the issue and let you continue to use AGP 7.1.0.

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"

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)

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"

Hope this helped 🙏

Support me by becoming a Medium member 🥳, and get access to unique programming articles that will enhance you skills.

Become a Medium member — 🖖 Live long and prosper 🖖

Androidcomponentsextens
Gradle
Android
Recommended from ReadMedium