Gradle cannot create LibraryVariantBuilderImpl in a Flutter Android build
Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImplShort answer
This error appears when the Android Gradle plugin (AGP) cannot run in the Gradle or IDE you use. Check three version pairs: the Gradle wrapper must meet the minimum for your AGP, Android Studio must support your AGP, and the AGP version should be fixed, not a dynamic range like 8.+.
Fix it fast
1Find out which cause you have
Print the Gradle version the wrapper uses and the AGP version declared in your project, then compare them to the table in the AGP release page. Flutter can also do the comparison for you.
cd android && ./gradlew --version grep -rn "com.android" settings.gradle* build.gradle* grep distributionUrl gradle/wrapper/gradle-wrapper.properties cd .. && flutter analyze --suggestions2Match what you see, then jump to its fix
- 1
gradlew --version prints a Gradle below the minimum for the AGP version in settings.gradle(.kts)The Gradle wrapper is older than your AGP requiresFix - 2
The error shows only inside the IDE, or the IDE asks you to update AGP on opening the projectAndroid Studio is too old for the AGP versionFix - 3
A version string such as 8.+ or 9.5.+ in the plugin declarationThe AGP version is a dynamic range, so it changed under youFix
- 1
What does the error look like?
Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl
Cause 1 of 3
The Gradle wrapper is older than your AGP requires
1Check
Each AGP has a minimum Gradle: for example AGP 8.13 needs 8.13, AGP 9.0 needs 9.1.0 and AGP 9.3 needs 9.5.0. Compare your two versions to the table.
grep distributionUrl android/gradle/wrapper/gradle-wrapper.properties2Fix
Raise the wrapper to the version flutter analyze --suggestions names, or at least the AGP minimum. Flutter documents this command; run it twice if you also want the wrapper scripts themselves updated.
cd android
./gradlew wrapper --gradle-version=SOMEGRADLEVERSION3Verify
Rebuild from the project root.
flutter clean && flutter build apk --debugConfirmed by developer.android.com
Cause 2 of 3
Android Studio is too old for the AGP version
1Check
Each Android Studio release supports a range of AGP versions, for example Otter 3 Feature Drop supports 4.2 to 9.0. A project newer than the IDE range can fail to sync.
grep -rn "com.android.application" android/settings.gradle*2Fix
Update Android Studio to a release whose range includes your AGP, or lower the AGP version in settings.gradle(.kts) and use a Gradle that suits it.
# android/settings.gradle.kts, plugins block
id("com.android.application") version "8.13.0" apply false3Verify
Sync Gradle in the IDE and run the build once more.
flutter build apk --debugConfirmed by developer.android.com
Cause 3 of 3
The AGP version is a dynamic range, so it changed under you
1Check
Android's docs advise against dynamic versions, which can bring unexpected updates and make version mismatches hard to find.
grep -rn "[0-9]\.+" android/*.gradle* android/settings.gradle*2Fix
Write one exact AGP version and keep the Gradle wrapper at or above its minimum.
id("com.android.application") version "8.13.0" apply false3Verify
Run a clean build.
flutter clean && flutter build apk --debugConfirmed by developer.android.com
How do I stop it coming back?
- Upgrade AGP and the Gradle wrapper in the same commit.
- Run flutter analyze --suggestions after every Flutter upgrade.
- Never use + in plugin versions.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
Google Play says the app does not support 16 KB memory pages
check_elf_alignment.sh reports UNALIGNED for a library under lib/arm64-v8a
Google Play requires apps that target Android 15 or higher and ship native .so libraries to run on devices with 16 KB memory pages; from 1 February 2027 it will block updates that do not.
5 causes, each with a fixMobile apps
Gradle cannot find com.google.firebase:firebase-analytics-ktx
Required by: project :app
Firebase moved the Kotlin extensions into the main modules and stopped releasing the -ktx modules in July 2025.
2 causes, each with a fixMobile apps
Flutter release build cannot open the keystore: HmacPBESHA256 not available
Algorithm HmacPBESHA256 not available
The keystore is a PKCS12 file protected by a newer algorithm than the Java that is reading it understands.
3 causes, each with a fixMobile apps
Android install error: the package conflicts with an existing package of the same name
The package conflicts with an existing package by the same name
Android allows only one app per application ID, and an update must be signed with the same certificate as the installed version.
3 causes, each with a fixMobile apps
Android resource linking fails with resource android:attr/lStar not found
error: failed linking references.
The lStar attribute exists only from Android API 31.
2 causes, each with a fixMobile apps
Gradle cannot find the Android SDK on this machine
FAILURE: Build failed with an exception. What went wrong: SDK location not found.
Gradle looks for the Android SDK in the sdk.dir line of android/local.properties and in the ANDROID_HOME environment variable, and found neither.
4 causes, each with a fix