Unable to load class AndroidComponentsExtension after upgrading the Android Gradle Plugin 7.1
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.
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"
}
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"
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"
How to add classpath in new version of Android Studio
In the latest version in February 2022 doesn't need to add buildscript
anymore just add the id in build.gradle
for project. It will be like this in build.gradle
for project:
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'androidx.navigation.safeargs' version '2.4.1' apply false
// classpath are changed, so no need to add classpath anymore just the id and the version
}
Don't forget add the id again in the build.gradle
module,
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'androidx.navigation.safeargs'
}
New build.gradle in Android Studio Bumblebee | 2021.1.1 Beta 5 error adding dependencies
You can do this thing.
ext {
compose_version = '1.0.5'
kotlin_version = '1.6.10'
}
// 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 "$kotlin_version" apply false
id "com.google.dagger.hilt.android" version "2.41" apply false
id 'androidx.navigation.safeargs.kotlin' version '2.5.0-alpha01' 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
}
How to add project level dependency class path in Android Studio Bumblebee
Use this line:
id 'androidx.navigation.safeargs.kotlin' version '2.5.0-alpha01' apply false
- "classpath..." will not work in Bumblebee or newer version:
https://stackoverflow.com/a/70872516/3466808
https://stackoverflow.com/a/70857477/3466808
Android Gradle Plugin 7.2 ignores added proguard file in Android App build process
In Groovy the value can be set for android.defaultConfig
:
// this sets one file
android.defaultConfig { config ->
proguardFile new File("../general.pro")
}
// this adds an additional file
android.defaultConfig { config ->
proguardFiles.add(new File("../general.pro"))
}
// proof of concept
android.buildTypes { buildType ->
println buildType
}
This happens before :prepareKotlinBuildScriptModel
, which means early on.
Related Topics
How to Release Application Plugin Using Android Market
Lint Error "Do Not Treat Position as Fixed; Only Use Immediately..."
Android Multidex Support Library Using Eclipse
Convert Existing Project to Library Project in Android Studio
Android Class Parcelable with Arraylist
Speech to Text from Own Sound File
How to Pass Arraylist<Hashmap<String, String>>From One Activity to Another
How to Use Default Android Drawables
How Can Android Source Code Not Have a Main Method and Still Run
Opencv Image Comparison in Android
How to Delete Internal Storage File in Android
Setsupportactionbar Toolbar Cannot Be Applied to (Android.Widget.Toolbar) Error
Error When Using Any Android Design Support Library Elements